The Media Kit Table of Contents     The Media Kit Index

BMediaEncoder

Derived from: none

Declared in: be/media/MediaEncoder.h

Library: libmedia.so

Summary

The BMediaEncoder class is a base class from which encoder classes may be derived. It handles all the work of locating an appropriate encoder add-on and interfacing with it. All you have to do is implement the WriteChunk() and AddTrackInfo() functions to write a chunk of encoded data to the destination and to write information about the track into the file.

The BMediaBufferEncoder class is provided for you; it's a derived class that implements WriteChunk() to write encoded data into a memory buffer.

An application that wants to encode a stream of data that's not originating from a file should use a subclass of BMediaEncoder (such as BMediaBufferEncoder) to do so.


Hook Functions

AddTrackInfo()

WriteChunk()


Constructor and Destructor


BMediaEncoder()

                                                         
  

BMediaEncoder()

BMediaEncoder(const media_format *outputFormat)

The constructor sets up the BMediaEncoder. If you use the empty form of the constructor, you'll have to call SetTo() to establish the format to be encoded before calling encode().

The second form accepts a media_format structure, inFormat, that indicates the type of media data that will be input into the encoder.

The third form of the constructor accepts a media_codec_info structure, mci, that determines which codec should be used.

 
If you use either the media_format or media_codec_info form of the constructor, you must call InitCheck() to ensure that construction was successful before using any other functions in this class.



~BMediaEncoder()

                                                         
  

virtual ~BMediaEncoder()

Releases the encoder add-on being used by the BMediaEncoder.


Member Functions


AddTrackInfo()

protected:

                                                         
  

status_t AddTrackInfo(uint32 code, const char *data,
      size_t size)

In derived classes, you should implement this function to write track information into the output file. code indicates the type of information being added, and data is the information data itself. size indicates the size of the data to be written.

By default, this function returns B_ERROR. Your implementation should return B_OK if the information was written successfully; otherwise it should return an appropriate error code.


Encode()

                                                         
  

status_t Encode(void *inBuffer, int64 frameCount,
      media_encode_info *info)

Encodes a chunk of media data from the input buffer by inBuffer, which contains frameCount frames of data.

The media_encode_info structure info is used on input to specify encoding parameters.

After the data is encoded, the encoder will call the derived class' WriteChunk() function to write the data into the file.

RETURN CODES


GetEncodeParameters() , SetEncodeParameters()

                                                         
  

status_t GetEncodeParameters(encode_parameters *inParameters) const

status_t SetEncodeParameters(encode_parameters *outParameters)

GetEncodeParameters() returns in inParameters the encode_parameters describing how the encoder add-on is configured.

SetEncodeParameters() let you specify the encode_parameters for the add-on.

RETURN CODES


InitCheck()

                                                         
  

status_t InitCheck(void) const

Returns a status_t value indicating whether or not construction was successful. You must call this function after construction before calling any other BMediaEncoder functions.

RETURN CODES

  • B_OK. The constructor was successful.

  • SetTo() errors.


SetFormat()

                                                         
  

status_t SetInputFormat(media_format *inputFormat,
      media_format *outputFormat,
      media_file_format *mfi = NULL)

SetFormat() sets the input and output formats to be used by the encoder, as well as the media_file_format describing the file to which the encoded data will be written.

RETURN CODES

  • B_OK. No error.

  • B_NO_INIT. The BMediaEncoder hasn't been initialized yet.

  • Other errors. The encoder's SetFormat() function can return errors through SetFormat().


SetEncodeParameters() see GetEncodeParameters()


SetTo()

                                                         
  

status_t SetTo(const media_format *outputFormat)

status_t SetTo(const media_codec_info *mci)

SetTo() sets the format of media data that will be encoded by the BMediaEncoder object. This also causes the BMediaEncoder to locate an appropriate codec to use.

The first form accepts a media_format structure, outputFormat, that indicates the type of media data that the encoder should output.

The second form of SetTo() accepts a media_codec_info structure, mci, that determines which codec should be used.

RETURN CODES


WriteChunk()

protected:

                                                         
  

status_t WriteChunk(const void *chunkData, size_t chunkLength,
      media_encode_info *info) = 0

In derived classes, you should implement this function to write the chunk of encoded data pointed to by chunkData into the destination file or buffer. chunkLength indicates the size of the buffer, and info provides information about the encoding process that you might need to reference.

Return B_OK if the data is successfully written; otherwise return an appropriate error code.


The Media Kit Table of Contents     The Media Kit Index


The Be Book,
...in lovely HTML...
for BeOS Release 5.

Copyright © 2000 Be, Inc. All rights reserved..