📄 libmpeg2.txt
字号:
The documentation is currently a mess. Sorry about that, hope to writesomething better for the 0.5.0 release.For people migrating code from 0.3.x to 0.4.x, the biggest thing tonote is that mpeg2_parse now returns a new state STATE_BUFFER when itneeds more data. Version 0.3.x used to return a -1 constant for this -please update your code to replace that -1 with STATE_BUFFER. Otherwise0.3.x code should mostly work with 0.4.x, hopefully.For people new to libmpeg2, it's best to start by looking atdoc/sample1 and doc/sample2, which decode an mpeg2 elementary streamand output their individual pictures as yuv frames (sample1) or rgbframes (sample2). The main loop calls mpeg2_parse() which does somework and then returns a state indicating what it just did -STATE_BUFFER if it reached the end of the buffer and it needs a newone, STATE_SEQUENCE if it just parsed a sequence header, STATE_PICTUREif it just parsed a picture header, STATE_SLICE if it just decoded theslice information associated with a picture (now is a good time tosave that decoded picture), etc...To make more complex buffer management (basically allocate your ownbuffers instead of letting the lib do it for you), look atsample3/sample4 (giving your buffers to the lib at init time butletting the lib chose a buffer for each picture) or sample5/sample6(giving a new buffer to the lib for each picture).Color conversion has been moved to a new helper library, libmpeg2convert.The details of the mpeg2_convert_t type might change in the future,but what won't change is that you should just take one of thempeg2_convert_t symbols exported from libmpeg2convert, and pass it tothe mpeg2_convert() function, and voila, you now get your outputbuffers in the desired format. For example if you want rgb 32-bitsamples, you just call mpeg2_convert (mpeg2dec, mpeg2convert_rgb32, NULL)and that's it.There is a new mpeg2_stride function too. By default libmpeg2 chosesthe smallest stride that will work for a given picture size, if youwant a larger stride you can set it (after the sequence header hasbeen decoded) by calling mpeg2_stride.There is also a new function mpeg2_reset which should hopefully do theright thing after skipping to a new position in the mpeg2 stream. Iffull_reset is zero the lib starts decoding at the next picture, ifit's one the lib starts looking for the next sequence header.The mpeg2_pts function is gone, because people complained about notbeing to pass a 33-bit PTS thru it. So instead it's been replaced withmpeg2_tag_picture(), which is identical except that it allows you topass two 32-bit values. You can use them to form a combined 64-bittime stamp, or two 32-bit PTS/DTS stamps, or whatever you please -libmpeg2 never uses these values, it just passes them around, hencethe name "tag". The semantics are what you want for a PTS functionthough, i.e. the tags get associated to the next picture that startsafter the tag was set, where the start of a picture is defined as thefirst byte of its picture start code.That's all I can think of - sorry for the lack of properdocumentation, I'll try to help this before the 0.5.0 release.I - simplest exampleexplanation of sequence_t, picture_t fieldsII - w/ color conversionIII - ptsIV - app that preallocates buffersV - app that does its own buffer managementQuick-and-dirty documentation for libmpeg2 0.3.1Kees Cook <mpeg2@outflux.net>2003-04-25Basic Usage Pseudocode---------------------- if (you need a certain acceleration) mpeg2_accel(desired_acceleration); handle=mpeg2_init(); info=mpeg2_info(handle); while (data_available) { state=mpeg2_parse(handle); switch (state) { case STATE_BUFFER: read some data mpeg2_buffer(handle,data_start,data_end); break; case STATE_SLICE: case STATE_END: display the frame described in "info" break; case STATE_INVALID: abort break; } } mpeg2_close(handle);Basic Usage Explained---------------------libmpeg2 uses an opaque pointer which is the active "handle" to the mpeg2decoder. To get this handle (of type "mpeg2dec_t"), call "mpeg2_init()".Data is loaded into the decoder with "mpeg2_buffer" whenever"mpeg2_parse" is ready for more data (return state is STATE_BUFFER).Pictures are available whenever "mpeg2_parse"'s return state isSTATE_SLICE or STATE_END. This means the *previous* picture is available, right? In other words, when STATE_SLICE is seen, that means that the *previous* picture is all done. Same thing for STATE_END. So if you want to see one frame at a time (without starting to fill the mpeg2 decoder with more data not from that picture) we'd have to inject something to make it report STATE_END?Basic Function Reference------------------------mpeg2dec_t * mpeg2_init() Initializes a memory space for mpeg2 decoding. This memory must be freed with a call to "mpeg2_close" when finished. Returns NULL on error (when system is out of memory) - Doesn't check if chunk_buffer is NULL?uint32_t mpeg2_accel(uint32_t accel) Sets the CPU acceleration type to be used for all decoders for the life of the program. YOU CAN SAFELY IGNORE THIS FUNCTION. By default, a call to mpeg2_accel is not needed, since the best available acceleration will be auto-detected. To override the default, this function must be called before any calls to "mpeg2_init". See mpeg2.h for a list of the available accelerations (prefix "MPEG2_ACCEL_..."). After a call to mpeg2_init, mpeg2_accel can be called to find out what the selected acceleration list is. Once the accelerations have been selected (through explicitly requesting one, or through auto-detection) the "accel" parameter will be ignored. Returns selected acceleration list. If the requested acceleration is not available, the function will auto-detect the best available accelerations and return that instead. - Cannot be undone! This should maybe be a part of the mpeg2 structure somehow?const mpeg2_info_t * mpeg2_info(mpeg2dec_t * handle) Gets structure for the mpeg2 decoder's "mpeg2_info_t" structure. This will let you do something (like display!) the decoded pictures with the mpeg2_info_t structure members: display_fbuf: memory area containing the rendered picture information. If this is NULL, no frame is available. display_fbuf->buf: YUV coded pixel data for the picture. display_picture: data structure describing the current picture. see mpeg2.h for more details. sequence: data structure describing the entire current picture sequence: width: picture width in pixels. height: picture height in pixels. see mpeg2.h for more details. user_data: handy place to attach things needed by your program. Must be detached before calling "mpeg2_close". there are more...check mpeg2.hint mpeg2_parse(mpeg2dec_t * handle) Parses available data and returns state of the decoder: STATE_BUFFER: ready for more data. decoder has finished reading the buffer sent with mpeg2_buffer. STATE_SEQUENCE: A sequence header has been found. STATE_SEQUENCE_REPEATED: A repeated sequence header has been found and processed. STATE_GOP: A GOP has been found. STATE_PICTURE: A picture header has been found. STATE_PICTURE_2ND: A second field picture header has been found. STATE_SLICE_1ST: First slice of a multi-field picture has been found. STATE_SLICE: Final slice (multi-field or not) of a picture has been found. Good time to update the display. STATE_END: End of the stream? Good time to update the display. STATE_INVALID: Filled the internal buffers without finding any start codes. Cannot continue: mpeg2_close must be called next.void mpeg2_buffer(mpeg2dec_t * handle, uint8_t * start, uint8_t * end) Makes data between "start" and "end" available for processing. If a subsequent call to "mpeg2_parse" doesn't find anything useful (returns STATE_BUFFER) then this data will be copied into the mpeg2 decoder's private data area. This process repeats until something useful is found with mpeg2_parse (returns something other than STATE_BUFFER), or the buffer fills up.void mpeg2_close(mpeg2dec_t * handle) Cleans up the memory associated with the mpeg2 decoder handle. - does not check for NULL frees! (via mpeg2_free)Advanced Function Reference---------------------------mpeg2_convertmpeg2_set_bufmpeg2_custom_fbufmpeg2_init_fbufmpeg2_slice
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -