Decoder object for key data structures Mad_decoder

Source: Internet
Author: User
Tags data structures error handling

Mad_decoder can be seen as the "core" structure of the entire decoder. It realizes some functions of object-oriented language by using the finite object mechanism of C language. The decoder encapsulates all the necessary components of a decoding process, including user-defined messages, 6 callback functions, and corresponding options. The mad_decoder structure is defined in the Decoder.h header file:

struct Mad_decoder {enum mad_decoder_mode mode; int options; struct {long pid; int in; int out;} async; struct {struct Mad_stream stream; struct Mad_frame frame; struct Mad_synth synth; } *sync; void *cb_data; Enum Mad_flow (*input_func) (void *, struct mad_stream *); Enum Mad_flow (*header_func) (void *, struct mad_header const *); Enum Mad_flow (*filter_func) (void *, struct mad_stream const *, struct mad_frame *); Enum Mad_flow (*output_func) (void *, struct mad_header const *, struct MAD_PCM *); Enum Mad_flow (*error_func) (void *, struct mad_stream *, struct mad_frame *); Enum Mad_flow (*message_func) (void *, void *, unsigned int *); };

Where the mode member has Mad_decoder_mode_sync and Mad_decoder_mode_async two values, respectively, specify synchronous and asynchronous two modes of operation; options that are brought into the stream of the sync member Async members carry State messages that are required for asynchronous decoding, and async members are populated by the input callback function and undergo the entire decoding process, regardless of whether they are synchronous or asynchronous; Cb_data is a user-defined message structure that is processed at the beginning of the decoding process (such as input, filter, output, Error handling, etc.), the following 6 callback functions can select the fill as needed, such as the most basic decoding to include at least input and output, the other callback functions are optional.

A Mad_decoder variable is typically initialized with the Mad_decoder_inti () function, as is done in the beginning and minimad.c of this article (this file can be found in a compressed package). The Mad_decoder variable can then be decoded using the Mad_decoder_run () function. The output callback function is constantly called during decoding (one MP3 frame per decode) until all valid frames are decoded or an error that cannot be ignored is encountered, and the Mad_decoder_run () function returns.

Finally, use the Mad_decoder_finish () function to do the final cleanup work.

The encapsulation of Mad_decoder is not a strict encapsulation. The members are completely visible to the outside, but in the process of processing a decoding process as a whole, wherein the components exist in the Mad_decoder object. is not strictly object-oriented in the sense of "is a ..." and "has a ...".

Finally we go back to the origin--6 callback functions. We will focus on them in the following chapters.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.