mux_mp2.h
上传用户:wangqun
上传日期:2019-10-16
资源大小:34701k
文件大小:24k
- /* ----------------------------------------------------------------------------
- * File: mux_mp2.h
- *
- * Desc: MPEG Muxer API
- *
- * Copyright (c) 2009, MainConcept GmbH. All rights reserved.
- *
- * This software is the confidential and proprietary information of
- * MainConcept GmbH and may be used only in accordance with the terms of
- * your license from MainConcept GmbH.
- * ----------------------------------------------------------------------------
- */
-
- #if !defined (__MUX_MP2_API_INCLUDED__)
- #define __MUX_MP2_API_INCLUDED__
- #include "bufstrm.h"
- #include "mcdefs.h"
- #include "mcprofile.h"
- #include "mcmediatypes.h"
- #include "mcapiext.h"
- typedef struct MP2Muxer mp2muxer_tt; // muxer object
- //namespace MP2Mux
- //{
- // maximum stream of each type that can be added
- // Don't use these defines anymore - obsolete parameters.
- // Kept for compatibility reasons only.
- // The maximum allowed number of streams is limited by the specs for concrete output profile (TS, PS, etc.)
- #define MAX_VIDEO_STREAMS 8
- #define MAX_AUDIO_STREAMS 8
- #define MAX_SUBPIC_STREAMS 32
- // -------------------------------
- // flags for the mp2muxer_set_struct.feature_flags field
- #define MUX_FEATURE_TS_ATS 0x00000001 // add 4-byte arrival time stamp prefix to all transport stream packets
- // only the lower 30 bits of the 4 bytes are used
- // the upper 2 bits are set to 0
- #define MUX_FEATURE_TS_NO_PSI 0x00000002 // no transport stream Program Specific Information (PAT, PMT, etc.)
- // is placed in the transport stream
- #define MUX_FEATURE_TS_AU_INFO 0x00000004 // AU_information private data as defined by ETSI TS 101 154 V1.7.1
- // is placed in the transport stream
- #define MUX_FEATURE_TS_PCR_IFRAMES 0x00000008 // PCR is placed in transport stream packets that contain the start
- // of an I or IDR frame
- #define MUX_FEATURE_TS_PCR_ALL_FRAMES 0x00000010 // PCR is placed in transport stream packets that contain the start
- // of any frame
- // flags for the mp2mux_stream_set_struct.flags field
- #define STREAM_FLAG_STILL_PICTURES 0x00000001 // video stream contains still images, I frames only!
- #define STREAM_FLAG_VCD_VBV_UPDATE 0x00000002 // only use with a single I frame, STREAM_FLAG_STILL_PICTURES
- // must also be present. The muxer will update the VBV in the
- // seq hdr to the length of the pic rounded up to a multiple
- // of 2048 bytes (as well as the P-STD buffer).
- #define STREAM_FLAG_SVCD_STILL_OFFSET 0x00000004 // put a SVCD scan offset in the still picture
- // STREAM_FLAG_STILL_PICTURES must also be present
- #define STREAM_FLAG_SUBPIC_WITH_PTS 0x00000008 // each subpic is prefixed by an 8 byte (int64_t) PTS value, file mux only!
- #define STREAM_FLAG_H264_AU_DELIMITER 0x00000010 // put an AU delimiter before each H.264 frame
- #define STREAM_FLAG_STOP_AT_EOF 0x00000020 // stop muxing when this file ends, file muxing only, video or audio only
- //These defines are only informative since 8.0 and kept for backward compatibility only
- //Use mcmediatypes_t instead.
- #define STREAM_FLAG_VIDEO_STREAM 0x00010000 // stream is a video stream
- #define STREAM_FLAG_AUDIO_STREAM 0x00020000 // stream is an audio stream
- #define STREAM_FLAG_SUBPIC_STREAM 0x00040000 // stream is a subpicture stream
- // flags for the mp2mux_ext_set_struct.flags field
- #define EXT_FLAG_EMPTY_SECTORS 0x00000001 // make empty sectors instead of padding sectors, VCD only
- #define EXT_OUTPUT_DATA_FOR_XML 0x00000002 // output video_seq_info_xml and video_au_info_xml data
- #define EXT_USE_PROGRAM_NUMBER 0x00000010 // obsolete. Use mp2mux_ts_program_set_struct.program_number
- #define EXT_USE_NETWORK_ID 0x00000020 // obsolete. Set the network_ID to 0 to calculate it automatically, otherwise it's considered as valid value
- #define EXT_USE_TRANSPORT_ID 0x00000040 // obsolete. Set the transport_ID to 0 to calculate it automatically, otherwise it's considered as valid value
- #define EXT_PAD_PES_EXTENSION 0x00000080 // add 3 PES padding bytes to reserve space for a PES
- // extension in the first packet of each stream in a VOBU
- // mplex_type must be one of the DVD types!
- #define EXT_AUDIO_NO_SPAN_VOBU 0x00000100 // do not let an audio frame span a VOBU
- // boundary. mplex_type must be one of the DVD types
- #define EXT_PTS_START_OFFSETS 0x00000200 // streaming input PTS's start with offset,
- // adjust SCR start accordingly, leave audio PTS untouched
- #define EXT_WARN_ON_LOW_MUXRATE 0x00000400 // call wrn_printf (instead of calling inf_printf,
- // if the user mux rate is computed to be too low
- #define EXT_ERR_ON_LOW_MUXRATE 0x00000800 // call err_printf and abort (instead of calling inf_printf and continuing),
- // if the user mux rate is computed to be too low
- //obsolete flag
- #define EXT_PRESERVE_TIMESTAMPS 0x00001000 // use the streaming input timestamps without modification
- // On-the-fly parameters flags
- #define OTF_FLAG_BITRATE 0x00000001
- #define OTF_FLAG_PADDING 0x00000002
- #define MUX_OK 0
- #define MUX_NOVID 1
- #define MUX_NOAUD1 2
- #define MUX_NOAUD2 4
- #define MUX_NOTHINGTODO 8
- #define MUX_ERR 16
- #define MUX_NOSP 32
- #define MUX_NOTIMP 64
- #ifdef __GNUC__
- #pragma pack(push,1)
- #else
- #pragma pack(push)
- #pragma pack(1)
- #endif
- struct dash_vr_set_struct
- {
- unsigned char dci_cci_ss;
- unsigned char dci;
- unsigned char cci;
- unsigned char mnf_id[32];
- unsigned char mnfi_dt[1944];
- };
- struct si_commit_struct
- {
- int64_t target_time_PCR; //the PCR time at which SI config should be applied. In 27 MHz units.
- uint8_t reserved[128];
- };
- typedef enum
- {
- eOuter_descriptor_loop = 0, //descriptor loop of a PSI section
- eInner_descriptor_loop = 1 //descriptor loop of entries
- #ifdef __BORLANDC__
- eDummy = 0xffffffff
- #endif
-
- } loop_level_enum;
- struct si_descriptor_struct
- {
- int16_t target_table_id; //target table to which the descriptor should be loaded.
- int16_t target_table_id_ext; //target table id extension. Set to -1 if it's not required
- //It's excessive for such tables as PAT, since table_id = 0x0 is enough for distinguishing of this table;
- //But if many tables can exist with the same table_id (PMT for ex.), we need to distinguish between
- // tables using target_table_id_ext.
- //Example: for NIT the target_table_id_ext represents network_id.
- //For PMT specify the program_number as the target_table_id_ext.
-
- loop_level_enum target_loop; //inner loop (1) / outer loop (0). Use loop_level_enum.
- int16_t target_entry_id; //use it only if target_loop == 1! It's the PId of the stream,
- //for which the descriptor is written.
- int16_t target_entry_id_ext; //it's excessive for most of all entries, such as PMT entry. But NIT entry is identified by two id's - transport_id and orig_network_id
- uint8_t descriptor_tag;
- uint8_t descriptor_length;
- uint8_t* pbData; //pointer to the data. It is copied instantly into the internal muxer's memory.
- //User is responsible for cleaning of memory by himself.
- uint8_t reserved[32];
- };
- struct si_entry_struct
- {
- int16_t target_table_id; //target table to which the entry should be loaded.
- int16_t target_table_id_ext; //target table id extension. Set to -1 if it's not required
- int32_t entry_length; //length of the entry bytes (num of valid bytes by pbData)
- uint8_t* pbData; //pointer to the data. It is copied instantly into the muxer's internal memory.
- //User is responsible for cleaning of memory by himself!
- uint8_t reserved[32];
- };
- // Not implemented yet!
- //complete SI table to be multiplexed
- struct si_section_struct
- {
- int16_t target_table_id; //target table to which the descriptor should be loaded.
- int16_t target_table_id_ext; //target table id extension. Set to -1 if it's not required
- uint8_t* pbData; //pointer to the data. It is copied instantly into the internal muxer's memory.
- //User is responsible for cleaning of memory by himself.
- uint32_t cbData; //data size.
- uint8_t reserved[32];
- };
- struct mp2mux_stream_set_struct
- {
- mc_stream_format_t format_struct; // mc_mediatype and format structure: video, audio or user-defined private
- int32_t stream_fifo_size; // the size of the fifo in bytes being used for this stream, only used
- // by mpegOutMP2MuxAddStream. If 0, the muxer will use a fixed size
- // for its internal fifo, else the muxer will compute an appropriate
- // internal fifo size based on this value
- int32_t stream_rate_bps; // Optional field. Sets the bitrate of the stream.
- // If the input media type is private or doesn't contain any headers (i.e. PCM, subpicture),
- // the bitrate must be specified by this parameter.
- // It also effective for 'parsable' video / audio: this parameter is applied with higher priority than
- // the bitrate specified in the bitstream.
- int32_t delay_ms; // stream delay, 0 = automatically computed
- int32_t id; // stream ID, 0 = automatically computed
- int32_t PES_length;
- int32_t parent_program_PID;
- int32_t flags; // flags, one or more of the STREAM_FLAGS_ defines above
- // The best way to specify the mediatype is to use the format_struct.
- // If it's not possible or format_struct is not filled at all, this parameter
- // MUST contain one and only one of: STREAM_FLAG_VIDEO_STREAM, STREAM_FLAG_AUDIO_STREAM or STREAM_FLAG_SUBPIC_STREAM
- int32_t still_picture_duration; // duration of still pictures if the STREAM_FLAG_STILL_PICTURES flags
- // is present. The value is the number of frames to display each picture
- // ***** TS specific ***********
- int32_t PID; // PID, 0 = automatically computed
- // ***** PS specific ***********
- int32_t PSTD_buffer_size; // P-STD buffer size, 0 = automatically computed
- int32_t sub_id; // substream ID, 0 = automatically computed
-
- uint8_t shared_mpts_stream_flag; //set to 1 to indicate the stream is shared among all the programs being multiplexed
- int32_t cpb_size_bits;
- uint8_t align_in_flag;
- uint8_t opt_packing_flag;
- uint8_t enhanced_parsing_flag;
- uint8_t reserved[56];
- };
- typedef enum running_status_t
- {
- e_undefined = 0,
- e_not_running = 1,
- e_starts_few_sec = 2,
- e_pausing = 3,
- e_running = 4,
- e_reserved = 5
- };
- struct mp2mux_ts_program_set_struct
- {
- int32_t PCR_PID;
- int32_t independent_PCR_PID;
- int32_t independent_PCR_PID_flag;
- int32_t program_number;
- int32_t program_PID;
- uint8_t reserved5[64]; //63 or 60 and 4 bytes for independent PCR_PID?
- };
- struct mp2mux_ext_set_struct
- {
- uint32_t flags; // flags, one or more of the EXT_FLAG_ defines above
- // transport stream items
- int32_t NIT_PID; // network information section PID, 0 = automatically computed
- int32_t SDT_PID; // service description section PID, 0 = automatically computed
- int32_t EIT_PID; // event information section PID, 0 = automatically computed
- int32_t TDT_PID; // time and date section PID, 0 = automatically computed
- // int PMT_PID; // obsolete; use mp2mux_ts_program_set_struct.program_PID
- // int PCR_PID; // obsolete; use mp2mux_ts_program_set_struct.PCR_PID
- // int program_number; // obsolete; use mp2mux_ts_program_set_struct.program_number
- int32_t PSI_LIMIT; // time (in ms) before the PAT and other tables are repeated, 0 = automatically computed
- int32_t PCR_LIMIT; // upper limit (in ms) of the PCR repeat rate, 0 = automatically computed
-
- int32_t network_id; // transport stream network id. Set to 0 to be automatically computed
- int32_t transport_id; // transport stream id. Set to 0 to be automatically computed
-
- struct dash_vr_settings *dvr_set; // DVD-VR settings
- uint8_t reserved[40];
- };
- struct mp2muxer_set_struct
- {
- int32_t mplex_type; // type of program stream, one of the MPEG_ defines in mcdefs.h
- int64_t sectors_delay; // time stamp of first mpeg pack in ms
- int64_t video_delay_ms; // default time stamp of the first video packet for all video streams, 0 = automatically computed
- int64_t audio_delay_ms; // default time stamp of the first audio packet for all audio streams, 0 = automatically computed
- int32_t sector_size; // size of the mpeg packs
- int32_t packets_per_pack; // number of PES packets per pack
- int32_t extra_padding_packs; // extra padding packets per second for transport streams only
- int32_t user_mux_rate_bps; // force a particular mux rate (in bps)
- int32_t vcd_audio_pad; // pad each vcd audio sector with 20 zeros
- int32_t align_sequence_headers; // align sequence headers to the start of a PES packet
- int32_t put_private2; // put DVD private stream 2's instead of padding packets
- int32_t frame_timestamps; // which frames to timestamp
- int32_t VBR_multiplex; // do VBR style multiplexing (enable / disable padding in both TS / PS)
-
- int32_t mux_SVCD_scan_offsets; // compute SVCD scan offsets
- int32_t max_file_size; // split file every so many MB
- uint32_t feature_flags; // one or more of the MUX_FEATURE_* defines
- int32_t reset_clocks; // reset the clocks in split files
- int32_t write_pec; // write a program end code
- int32_t write_end_codes; // write program end codes in split files
- int32_t set_broken_link; // set the broken link flag in the first GOP of split files
- uint8_t ts_write_PSI_only_once; // Write the PSI (PAT, PMT, etc) only once in the beginning of the stream
- uint8_t ts_set_disc_indicator; // Set the 'discontinuity_indicator' of the first TS packet to 1
- uint8_t deny_missing_streams; // do not allow muxing of data when the input buffer is full. This can be done if only EOS received in case if deny_missing_stream=1
- uint8_t reserved[125];
- };
- #define MP2MUX_RT_FLAG_BITRATE 1 << 31;
- struct mp2mux_rt_set
- {
- int32_t user_mux_rate_bps; // force a particular mux rate (in bps)
- int32_t VBR_multiplex; // do VBR style multiplexing (enable / disable padding in both TS / PS)
- };
- #pragma pack(pop)
- #ifdef __cplusplus
- extern "C" {
- #endif
- // call to fill an mp2muxer_set_struct structure with defaults values
- // based on one of the SDK profile ID's
- //
- // inputs:
- // set - pointer to an mp2muxer_set_struct structure
- // video_type - one of the MPEG_* constants
- // output:
- // modified mp2muxer_set_struct structure
- // return:
- // none
- char *mpegOutMP2MuxDefaults(struct mp2muxer_set_struct *set, int32_t profileID);
- // call to create an mpeg muxer object
- //
- // inputs:
- // get_rc - pointer to a get resource function
- // set - pointer to a filled in mp2muxer_set_struct structure
- // outputs:
- // none
- // return:
- // pointer to a mp2muxer_tt object if succesful
- // NULL if unsuccesful
- mp2muxer_tt * mpegOutMP2MuxNew(void *(*get_rc)(char* name), const struct mp2muxer_set_struct *set);
- // call to initialize the muxer for a streaming mode muxing session,
- // the audio/video data comes from audio and video bufstream
- // objects passed to mpegOutMP2MuxAddStream
- //
- // inputs:
- // muxer - pointer to an mpeg muxer object
- // output - pointer to a bufstream_tt object for the output muxed data
- // ext_set - pointer to an mp2mux_ext_set_struct structure, can be NULL
- // outputs:
- // none
- // return:
- // MUX_OK if successful
- // MUX_ERR if unsuccesful
- int32_t mpegOutMP2MuxInitStream(mp2muxer_tt *muxer, struct mp2mux_ext_set_struct *ext_set, bufstream_tt *output);
- // call to add a video, audio or subpic stream to the muxer in streaming mode,
- //
- // inputs:
- // muxer - pointer to an mpeg muxer object
- // set - pointer to a mp2mux_stream_set_struct structure
- // input - pointer to a bufstream_tt object for the input data
- // outputs:
- // none
- // return:
- // MUX_OK if successful
- // MUX_ERR if unsuccesful
- int32_t mpegOutMP2MuxAddStream(mp2muxer_tt *muxer, struct mp2mux_stream_set_struct *set, bufstream_tt *input);
- // call to initialize the muxer for a file mode muxing session,
- // the audio/video data comes from files added via mpegOutMuxAddFile
- //
- // inputs:
- // muxer - pointer to an mpeg muxer object
- // output - pointer to an output filename or bufstream for the output muxed data
- // ext_set - pointer to an mp2mux_ext_set_struct structure, can be NULL
- // outputs:
- // none
- // return:
- // MUX_OK if successful
- // MUX_ERR if unsuccesful
- int32_t mpegOutMP2MuxInitFile(mp2muxer_tt *muxer, struct mp2mux_ext_set_struct *ext_set, char *output);
- int32_t mpegOutMP2MuxInitFileBS(mp2muxer_tt *muxer, struct mp2mux_ext_set_struct *ext_set, bufstream_tt *output);
- // call to add a video, audio or subpic stream to the muxer in file mode,
- //
- // inputs:
- // muxer - pointer to an mpeg muxer object
- // set - pointer to a mp2mux_stream_set_struct structure
- // input - pointer to a filename for the input data
- // input1, input2 - input bufstreams, same file opened twice
- // video_bitrate - bitrate (in bits/sec) of the video stream, only needed for MPEG-1 VBR or H264 video
- // also used for AAC audio streams!
- // outputs:
- // none
- // return:
- // MUX_OK if successful
- // MUX_ERR if unsuccesful
- int32_t mpegOutMP2MuxAddFile(mp2muxer_tt *muxer, struct mp2mux_stream_set_struct *set, char *input, int32_t video_bitrate);
- int32_t mpegOutMP2MuxAddFileBS(mp2muxer_tt *muxer, struct mp2mux_stream_set_struct *set, bufstream_tt *input1, bufstream_tt *input2, int32_t video_bitrate);
- // call to do the multiplexing in file mode
- //
- // inputs:
- // muxer - pointer to an mpeg muxer object
- // outputs:
- // muxed data to output file
- // return:
- // MUX_OK if succesful
- // MUX_ERR if unsuccesful
- int32_t mpegOutMP2Mux(mp2muxer_tt *muxer);
- // call to finish a muxing session, set abort non-zero if muxing is being
- // aborted.
- //
- // inputs:
- // muxer - pointer to an mpeg muxer object
- // abort - set to 0 to finish any leftover muxing and clean up,
- // else just clean up
- // outputs:
- // muxed data to output file if needed
- // return:
- // MUX_OK if successful
- // MUX_ERR if unsuccesful
- int32_t mpegOutMP2MuxDone(mp2muxer_tt *muxer, int32_t abort);
- // call to free an mpeg muxer object
- //
- // inputs:
- // muxer - muxer object to free
- // outputs:
- // none
- // return:
- // none
- void mpegOutMP2MuxFree(mp2muxer_tt *muxer);
- // call to get the setting errors/warnings in an mp2muxer_set_struct structure
- // use with the get_rc callback to provide an err_printf callback to get
- // error messages that can be localized
- //
- // inputs:
- // get_rc - pointer to a get_rc function
- // set - pointer to an mp2muxer_set_struct structure
- // options - check options, one or more of the CHECK_* defines in mcdefs.h
- // app - reserved
- // outputs:
- // none
- // return:
- // MUX_OK if no errors found
- // one of the INV_* error codes if an error is found
- int32_t mpegOutMP2MuxChkSettings(void *(*get_rc)(char *name), const struct mp2muxer_set_struct *set, uint32_t options, void *app);
- // call to send messages to the muxer
- //
- // inputs:
- // muxer - pointer to an mpeg muxer object
- // offs - value is dependent on the message
- // info_ID - the message to process
- // info_ptr - pointer, dependent on the message
- // info_size - size of the structure pointed to by info_ptr
- // outputs:
- // none
- // return:
- // none
- void mpegOutMP2MuxAuxinfo(mp2muxer_tt *muxer, int32_t offs, int32_t info_ID, void *info_ptr, int32_t info_size);
- // call to create a new TS program
- //
- // inputs:
- // muxer - pointer to an mpeg muxer object
- // program_set - pointer to the program's settings structure
- // return:
- // MUX_OK if all is ok
- // MUX_ERR if any error occured
- int32_t mpegOutMP2MuxAddProgram(mp2muxer_tt *muxer, struct mp2mux_ts_program_set_struct *program_set);
- // call to load a descriptor into an SI table
- // muxer - pointer to an mpeg muxer object
- // descriptor - pointer to the descriptor struct with all necessary info
- // outputs:
- // none
- // return:
- // MUX_OK if success, MUX_ERR otherwise
- int32_t mpegOutMP2MuxLoadDescriptor(mp2muxer_tt* muxer, const si_descriptor_struct* descriptor);
- // Not implemented yet!
- // call to load an Entry into an SI table
- // muxer - pointer to an mpeg muxer object
- // ts_entry - pointer to the entry struct with all necessary info
- // outputs:
- // none
- // return:
- // MUX_OK if success, MUX_ERR otherwise
- int32_t mpegOutMP2MuxLoadEntry(mp2muxer_tt* muxer, const si_entry_struct* entry);
- // Not implemented yet!
- // call to load a complete SI section
- // muxer - pointer to an mpeg muxer object
- // table - pointer to the descriptor struct with all necessary info
- // outputs:
- // none
- // return:
- // MUX_OK if success, MUX_ERR otherwise
- int32_t mpegOutMP2MuxLoadSection(mp2muxer_tt* muxer, const si_section_struct* descriptor);
- // call to commit loading of the descriptors / entries / sections set
- // muxer - pointer to an mpeg muxer object
- // commit_struct - pointer to the si_commit_struct with timing parameters declaring the moment of the new PSI info applying
- // If target_time_PCR == -1, then parameters are applied immediately
- // outputs:
- // none
- // return:
- // MUX_OK if success, MUX_ERR otherwise
- int32_t mpegOutMP2MuxCommitPSI(mp2muxer_tt* muxer, const si_commit_struct* commit_struct);
- //call to start streaming.
- //return:
- // MUX_OK if success, MUX_ERR otherwise
- int32_t mpegOutMP2MuxRun(mp2muxer_tt *muxer);
- // call to fill an mp2mux_ext_set_struct structure with defaults values
- // based on one of the SDK profile ID's
- //
- // inputs:
- // ProfileID - one of the MC profiles as defined in mcprofiles.h
- // output:
- // modified mp2mux_ext_set_struct structure
- // return:
- // none
- char *mpegOutMP2MuxDefaultsExt(struct mp2mux_ext_set_struct *set, int32_t profileID);
- // call to check whether the given stream is allowed for multiplexing into the specific TS profile
- // mc_stream_format_t as defined in mcmediatypes.h
- // one of the MPEG_ defines in mpegdef.h
- int32_t mpegOutMP2MuxCheckConnect(void *(*get_rc)(char* name), mc_stream_format_t *pFormat, int32_t mplex_type, void* pExt);
- // call to change the parameters "on-the-fly".
- // The parameters allowed to be modified are presented in the mp2mux_rt_set struct
- int32_t mpegOutMP2MuxRuntimeConfig(mp2muxer_tt *muxer, const mp2mux_rt_set* set, const uint32_t option_flags);
- // call to get extended API function
- //
- // inputs:
- // func - function ID
- // return:
- // function pointer or NULL
- APIEXTFUNC mpegOutMP2MuxGetAPIExt(uint32_t func);
- #ifdef __cplusplus
- }
- #endif
- #endif // #if !defined (__MUX_MP2_API_INCLUDED__)