Collaboration diagram for Banked Memory:
Even with a hardware decoder like the one used on the Medianut Board, streaming MP3 data in realtime from a TCP/IP network to the decoder requires some special techniques to make it work on a tiny 8 bit system.
The key to success is avoidance of data copying. Usually data streams are moved from the Ethernet Controller to the Ethernet's driver buffer, then moved to the TCP buffer, again moved to the application buffer and finally from the application buffer to the MP3 decoder buffer. Some systems may use additional steps. Nut/OS tries to avoid these copies. In extreme, the data may be moved directly from the Ethernet controller to the MP3 controller. In reality this will fail, because TCP isn't realtime, but playing MP3 is. So at least one buffer stage is required to compensate the non deterministic arrival of TCP data. Each packet received is moved from the Ethernet controller into a so called NETBUF. Each NETBUF is added to a connection specific queue until the application request data from the connection. For portability reasons and to keep things simple, the application provides a buffer and calls NutTcpReceive() to get that buffer filled with application data out of the queued NETBUFs. This is another copy, but frees the application from dealing with system specific NETBUF structures.
The smart part is, that Nut/OS offers a special buffer management to avoid the final copy into the decoder buffer and that the Nut/OS MP3 decoder driver makes use of this buffer management. As stated, normally the application buffer is filled by some kind of read statement (first copy) and transfered to the driver by some kind of write statement (second copy).
When using the segmented memory management, the application will query the driver for buffer space first and then pass this buffer to the TCP read routine. This way the TCP read routine will directly fill the buffer of the decoder driver. When this has been done, the application commits the buffer filled and requests a new one and so on.
Finally the segmented memory mamagement API can not only handle a continuos memory space, but also one that is divided into several segments. This is usefull with banked memory hardware provided by Ethernut 2 boards.
Functions | |
char * | NutSegBufReset (void) |
Reset the segmented buffer. | |
char * | NutSegBufInit (size_t size) |
Initialize the segmented buffer. | |
char * | NutSegBufWriteRequest (size_t *bcp) |
Request segmented buffer space for writing. | |
char * | NutSegBufReadRequest (size_t *bcp) |
Request segmented buffer space for reading. | |
char * | NutSegBufWriteCommit (u_short bc) |
Commit written buffer space. | |
char * | NutSegBufReadCommit (size_t bc) |
Commit read buffer space. | |
void | NutSegBufWriteLast (u_short bc) |
Commit written buffer space and finish write access. | |
void | NutSegBufReadLast (u_short bc) |
Commit written buffer space and finish read access. | |
u_long | NutSegBufAvailable (void) |
Return the available buffer space. | |
u_long | NutSegBufUsed (void) |
Return the used buffer space. |
|
Reset the segmented buffer.
|
|
Initialize the segmented buffer.
|
|
Request segmented buffer space for writing. This call will also enable the current write segment and may disable the current read segment.
|
|
Request segmented buffer space for reading. This call will also enable the current read segment and may disable the current write segment.
|
|
Commit written buffer space. The write pointer will be incremented by the specified number of bytes. If the pointer reaches the end of a segment, the next segment will be enabled and the pointer will point to the start of the new segement.
|
|
Commit read buffer space. The read pointer will be incremented by the specified number of bytes. If the pointer reaches the end of a segment, the next segment will be enabled and the pointer will point to the start of the new segement.
|
|
Commit written buffer space and finish write access. The write pointer will be incremented by the specified number of bytes. This call will also enable the current read segment and may disable the current write segment.
|
|
Commit written buffer space and finish read access. The write pointer will be incremented by the specified number of bytes. This call will also enable the current read segment and may disable the current write segment.
|
|
Return the available buffer space.
|
|
Return the used buffer space.
|