/* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited
Written by Jean-Marc Valin and Koen Vos */ /* Redistributionanduseinsourceandbinaryforms,withorwithout modification,arepermittedprovidedthatthefollowingconditions aremet:
/** Gets the size of an <code>OpusEncoder</code> structure. *@param[in]channels<tt>int</tt>:Numberofchannels. *Thismustbe1or2. *@returnsThesizeinbytes. *@noteSincethisfunctiondoesnottaketheapplicationasinput,itwilloverestimate *thesizerequiredforOPUS_APPLICATION_RESTRICTED_SILKandOPUS_APPLICATION_RESTRICTED_CELT. *Thatisgenerallynotaproblem,exceptwhentryingtoknowthesizetouseforacopy.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_encoder_get_size(int channels);
/** Frees an <code>OpusEncoder</code> allocated by opus_encoder_create(). *@param[in]st<tt>OpusEncoder*</tt>:Statetobefreed.
*/
OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st);
/** Perform a CTL function on an Opus encoder. * *Generallytherequestandsubsequentargumentsaregenerated *byaconveniencemacro. *@paramst<tt>OpusEncoder*</tt>:Encoderstate. *@paramrequestThisandallremainingparametersshouldbereplacedbyone *oftheconveniencemacrosin@refopus_genericctlsor *@refopus_encoderctls. *@seeopus_genericctls *@seeopus_encoderctls
*/
OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_ARG_NONNULL(1); /**@}*/
/** Gets the size of an <code>OpusDecoder</code> structure. *@param[in]channels<tt>int</tt>:Numberofchannels. *Thismustbe1or2. *@returnsThesizeinbytes.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels);
/** Allocates and initializes a decoder state. *@param[in]Fs<tt>opus_int32</tt>:Sampleratetodecodeat(Hz). *Thismustbeoneof8000,12000,16000, *24000,or48000. *@param[in]channels<tt>int</tt>:Numberofchannels(1or2)todecode *@param[out]error<tt>int*</tt>:#OPUS_OKSuccessor@refopus_errorcodes * *InternallyOpusstoresdataat48000Hz,sothatshouldbethedefault *valueforFs.However,thedecodercanefficientlydecodetobuffers *at8,12,16,and24kHzsoifforsomereasonthecallercannotuse *dataatthefullsamplerate,orknowsthecompresseddatadoesn't *usethefullfrequencyrange,itcanrequestdecodingatareduced *rate.Likewise,thedecoderiscapableoffillingineithermonoor *interleavedstereopcmbuffers,atthecaller'srequest.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_create(
opus_int32 Fs, int channels, int *error
);
/** Initializes a previously allocated decoder state. *Thestatemustbeatleastthesizereturnedbyopus_decoder_get_size(). *Thisisintendedforapplicationswhichusetheirownallocatorinsteadofmalloc.@seeopus_decoder_create,opus_decoder_get_size *Toresetapreviouslyinitializedstate,usethe#OPUS_RESET_STATECTL. *@param[in]st<tt>OpusDecoder*</tt>:Decoderstate. *@param[in]Fs<tt>opus_int32</tt>:Samplingratetodecodeto(Hz). *Thismustbeoneof8000,12000,16000, *24000,or48000. *@param[in]channels<tt>int</tt>:Numberofchannels(1or2)todecode *@retval#OPUS_OKSuccessor@refopus_errorcodes
*/
OPUS_EXPORT int opus_decoder_init(
OpusDecoder *st,
opus_int32 Fs, int channels
) OPUS_ARG_NONNULL(1);
/** Decode an Opus packet. *@param[in]st<tt>OpusDecoder*</tt>:Decoderstate *@param[in]data<tt>char*</tt>:Inputpayload.UseaNULLpointertoindicatepacketloss *@param[in]len<tt>opus_int32</tt>:Numberofbytesinpayload* *@param[out]pcm<tt>opus_int16*</tt>:Outputsignal(interleavedif2channels).length *isframe_size*channels*sizeof(opus_int16) *@param[in]frame_sizeNumberofsamplesperchannelofavailablespacein\apcm. *Ifthisislessthanthemaximumpacketduration(120ms;5760for48kHz),thisfunctionwill *notbecapableofdecodingsomepackets.InthecaseofPLC(data==NULL)orFEC(decode_fec=1), *thenframe_sizeneedstobeexactlythedurationofaudiothatismissing,otherwisethe *decoderwillnotbeintheoptimalstatetodecodethenextincomingpacket.ForthePLCand *FECcases,frame_size<b>must</b>beamultipleof2.5ms. *@param[in]decode_fec<tt>int</tt>:Flag(0or1)torequestthatanyin-bandforwarderrorcorrectiondatabe *decoded.Ifnosuchdataisavailable,theframeisdecodedasifitwerelost. *@returnsNumberofdecodedsamplesperchannelor@refopus_errorcodes
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode(
OpusDecoder *st, constunsignedchar *data,
opus_int32 len,
opus_int16 *pcm, int frame_size, int decode_fec
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Decode an Opus packet. *@param[in]st<tt>OpusDecoder*</tt>:Decoderstate *@param[in]data<tt>char*</tt>:Inputpayload.UseaNULLpointertoindicatepacketloss *@param[in]len<tt>opus_int32</tt>:Numberofbytesinpayload* *@param[out]pcm<tt>opus_int32*</tt>:Outputsignal(interleavedif2channels)representing(orslightlyexceeding)24-bitvalues.length *isframe_size*channels*sizeof(opus_int32) *@param[in]frame_sizeNumberofsamplesperchannelofavailablespacein\apcm. *Ifthisislessthanthemaximumpacketduration(120ms;5760for48kHz),thisfunctionwill *notbecapableofdecodingsomepackets.InthecaseofPLC(data==NULL)orFEC(decode_fec=1), *thenframe_sizeneedstobeexactlythedurationofaudiothatismissing,otherwisethe *decoderwillnotbeintheoptimalstatetodecodethenextincomingpacket.ForthePLCand *FECcases,frame_size<b>must</b>beamultipleof2.5ms. *@param[in]decode_fec<tt>int</tt>:Flag(0or1)torequestthatanyin-bandforwarderrorcorrectiondatabe *decoded.Ifnosuchdataisavailable,theframeisdecodedasifitwerelost. *@returnsNumberofdecodedsamplesor@refopus_errorcodes
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode24(
OpusDecoder *st, constunsignedchar *data,
opus_int32 len,
opus_int32 *pcm, int frame_size, int decode_fec
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Decode an Opus packet with floating point output. *@param[in]st<tt>OpusDecoder*</tt>:Decoderstate *@param[in]data<tt>char*</tt>:Inputpayload.UseaNULLpointertoindicatepacketloss *@param[in]len<tt>opus_int32</tt>:Numberofbytesinpayload *@param[out]pcm<tt>float*</tt>:Outputsignal(interleavedif2channels).length *isframe_size*channels*sizeof(float) *@param[in]frame_sizeNumberofsamplesperchannelofavailablespacein\apcm. *Ifthisislessthanthemaximumpacketduration(120ms;5760for48kHz),thisfunctionwill *notbecapableofdecodingsomepackets.InthecaseofPLC(data==NULL)orFEC(decode_fec=1), *thenframe_sizeneedstobeexactlythedurationofaudiothatismissing,otherwisethe *decoderwillnotbeintheoptimalstatetodecodethenextincomingpacket.ForthePLCand *FECcases,frame_size<b>must</b>beamultipleof2.5ms. *@param[in]decode_fec<tt>int</tt>:Flag(0or1)torequestthatanyin-bandforwarderrorcorrectiondatabe *decoded.Ifnosuchdataisavailabletheframeisdecodedasifitwerelost. *@returnsNumberofdecodedsamplesperchannelor@refopus_errorcodes
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode_float(
OpusDecoder *st, constunsignedchar *data,
opus_int32 len, float *pcm, int frame_size, int decode_fec
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Perform a CTL function on an Opus decoder. * *Generallytherequestandsubsequentargumentsaregenerated *byaconveniencemacro. *@paramst<tt>OpusDecoder*</tt>:Decoderstate. *@paramrequestThisandallremainingparametersshouldbereplacedbyone *oftheconveniencemacrosin@refopus_genericctlsor *@refopus_decoderctls. *@seeopus_genericctls *@seeopus_decoderctls
*/
OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
/** Frees an <code>OpusDecoder</code> allocated by opus_decoder_create(). *@param[in]st<tt>OpusDecoder*</tt>:Statetobefreed.
*/
OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st);
/** Gets the size of an <code>OpusDREDDecoder</code> structure. *@returnsThesizeinbytes.
*/
OPUS_EXPORT int opus_dred_decoder_get_size(void);
/** Allocates and initializes an OpusDREDDecoder state. *@param[out]error<tt>int*</tt>:#OPUS_OKSuccessor@refopus_errorcodes
*/
OPUS_EXPORT OpusDREDDecoder *opus_dred_decoder_create(int *error);
/** Initializes an <code>OpusDREDDecoder</code> state. *@param[in]dec<tt>OpusDREDDecoder*</tt>:Statetobeinitialized.
*/
OPUS_EXPORT int opus_dred_decoder_init(OpusDREDDecoder *dec);
/** Frees an <code>OpusDREDDecoder</code> allocated by opus_dred_decoder_create(). *@param[in]dec<tt>OpusDREDDecoder*</tt>:Statetobefreed.
*/
OPUS_EXPORT void opus_dred_decoder_destroy(OpusDREDDecoder *dec);
/** Perform a CTL function on an Opus DRED decoder. * *Generallytherequestandsubsequentargumentsaregenerated *byaconveniencemacro. *@paramdred_dec<tt>OpusDREDDecoder*</tt>:DREDDecoderstate. *@paramrequestThisandallremainingparametersshouldbereplacedbyone *oftheconveniencemacrosin@refopus_genericctlsor *@refopus_decoderctls. *@seeopus_genericctls *@seeopus_decoderctls
*/
OPUS_EXPORT int opus_dred_decoder_ctl(OpusDREDDecoder *dred_dec, int request, ...);
/** Gets the size of an <code>OpusDRED</code> structure. *@returnsThesizeinbytes.
*/
OPUS_EXPORT int opus_dred_get_size(void);
/** Allocates and initializes a DRED state. *@param[out]error<tt>int*</tt>:#OPUS_OKSuccessor@refopus_errorcodes
*/
OPUS_EXPORT OpusDRED *opus_dred_alloc(int *error);
/** Frees an <code>OpusDRED</code> allocated by opus_dred_create(). *@param[in]dec<tt>OpusDRED*</tt>:Statetobefreed.
*/
OPUS_EXPORT void opus_dred_free(OpusDRED *dec);
/** Decode an Opus DRED packet. *@param[in]dred_dec<tt>OpusDRED*</tt>:DREDDecoderstate *@param[in]dred<tt>OpusDRED*</tt>:DREDstate *@param[in]data<tt>char*</tt>:Inputpayload *@param[in]len<tt>opus_int32</tt>:Numberofbytesinpayload *@param[in]max_dred_samples<tt>opus_int32</tt>:MaximumnumberofDREDsamplesthatmaybeneeded(ifavailableinthepacket). *@param[in]sampling_rate<tt>opus_int32</tt>:Samplingrateusedformax_dred_samplesargument.Needsnotmatchtheactualsamplingrateofthedecoder. *@param[out]dred_end<tt>opus_int32*</tt>:Numberofnon-encoded(silence)samplesbetweentheDREDtimestampandthelastDREDsample. *@param[in]defer_processing<tt>int</tt>:Flag(0or1).Ifsettoone,theCPU-intensivepartoftheDREDdecodingisdeferreduntilopus_dred_process()iscalled. *@returnsOffset(positive)ofthefirstdecodedDREDsamples,zeroifnoDREDispresent,or@refopus_errorcodes
*/
OPUS_EXPORT int opus_dred_parse(OpusDREDDecoder *dred_dec, OpusDRED *dred, constunsignedchar *data, opus_int32 len, opus_int32 max_dred_samples, opus_int32 sampling_rate, int *dred_end, int defer_processing) OPUS_ARG_NONNULL(1);
/** Finish decoding an Opus DRED packet. The function only needs to be called if opus_dred_parse() was called with defer_processing=1. *ThesourceanddestinationwilloftenbethesameDREDstate. *@param[in]dred_dec<tt>OpusDRED*</tt>:DREDDecoderstate *@param[in]src<tt>OpusDRED*</tt>:SourceDREDstatetostarttheprocessingfrom. *@param[out]dst<tt>OpusDRED*</tt>:DestinationDREDstatetostoretheupdatedstateafterprocessing. *@returns@refopus_errorcodes
*/
OPUS_EXPORT int opus_dred_process(OpusDREDDecoder *dred_dec, const OpusDRED *src, OpusDRED *dst);
/** Decode audio from an Opus DRED packet with 16-bit output. *@param[in]st<tt>OpusDecoder*</tt>:Decoderstate *@param[in]dred<tt>OpusDRED*</tt>:DREDstate *@param[in]dred_offset<tt>opus_int32</tt>:positionoftheredundancytodecode(insamplesbeforethebeginningoftherealaudiodatainthepacket). *@param[out]pcm<tt>opus_int16*</tt>:Outputsignal(interleavedif2channels).length *isframe_size*channels*sizeof(opus_int16) *@param[in]frame_sizeNumberofsamplesperchanneltodecodein\apcm. *frame_size<b>must</b>beamultipleof2.5ms. *@returnsNumberofdecodedsamplesor@refopus_errorcodes
*/
OPUS_EXPORT int opus_decoder_dred_decode(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, opus_int16 *pcm, opus_int32 frame_size);
/** Decode audio from an Opus DRED packet with 24-bit output. *@param[in]st<tt>OpusDecoder*</tt>:Decoderstate *@param[in]dred<tt>OpusDRED*</tt>:DREDstate *@param[in]dred_offset<tt>opus_int32</tt>:positionoftheredundancytodecode(insamplesbeforethebeginningoftherealaudiodatainthepacket). *@param[out]pcm<tt>opus_int32*</tt>:Outputsignal(interleavedif2channels).length *isframe_size*channels*sizeof(opus_int16) *@param[in]frame_sizeNumberofsamplesperchanneltodecodein\apcm. *frame_size<b>must</b>beamultipleof2.5ms. *@returnsNumberofdecodedsamplesor@refopus_errorcodes
*/
OPUS_EXPORT int opus_decoder_dred_decode24(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, opus_int32 *pcm, opus_int32 frame_size);
/** Decode audio from an Opus DRED packet with floating point output. *@param[in]st<tt>OpusDecoder*</tt>:Decoderstate *@param[in]dred<tt>OpusDRED*</tt>:DREDstate *@param[in]dred_offset<tt>opus_int32</tt>:positionoftheredundancytodecode(insamplesbeforethebeginningoftherealaudiodatainthepacket). *@param[out]pcm<tt>float*</tt>:Outputsignal(interleavedif2channels).length *isframe_size*channels*sizeof(float) *@param[in]frame_sizeNumberofsamplesperchanneltodecodein\apcm. *frame_size<b>must</b>beamultipleof2.5ms. *@returnsNumberofdecodedsamplesor@refopus_errorcodes
*/
OPUS_EXPORT int opus_decoder_dred_decode_float(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, float *pcm, opus_int32 frame_size);
/** Parse an opus packet into one or more frames. *Opus_decodewillperformthisoperationinternallysomostapplicationsdo *notneedtousethisfunction. *Thisfunctiondoesnotcopytheframes,thereturnedpointersarepointersinto *theinputpacket. *@param[in]data<tt>char*</tt>:Opuspackettobeparsed *@param[in]len<tt>opus_int32</tt>:sizeofdata *@param[out]out_toc<tt>char*</tt>:TOCpointer *@param[out]frames<tt>char*[48]</tt>encapsulatedframes *@param[out]size<tt>opus_int16[48]</tt>sizesoftheencapsulatedframes *@param[out]payload_offset<tt>int*</tt>:returnsthepositionofthepayloadwithinthepacket(inbytes) *@returnsnumberofframes
*/
OPUS_EXPORT int opus_packet_parse( constunsignedchar *data,
opus_int32 len, unsignedchar *out_toc, constunsignedchar *frames[48],
opus_int16 size[48], int *payload_offset
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5);
/** Gets the bandwidth of an Opus packet. *@param[in]data<tt>char*</tt>:Opuspacket *@retvalOPUS_BANDWIDTH_NARROWBANDNarrowband(4kHzbandpass) *@retvalOPUS_BANDWIDTH_MEDIUMBANDMediumband(6kHzbandpass) *@retvalOPUS_BANDWIDTH_WIDEBANDWideband(8kHzbandpass) *@retvalOPUS_BANDWIDTH_SUPERWIDEBANDSuperwideband(12kHzbandpass) *@retvalOPUS_BANDWIDTH_FULLBANDFullband(20kHzbandpass) *@retvalOPUS_INVALID_PACKETThecompresseddatapassediscorruptedorofanunsupportedtype
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_bandwidth(constunsignedchar*data) OPUS_ARG_NONNULL(1);
/** Gets the number of samples per frame from an Opus packet. *@param[in]data<tt>char*</tt>:Opuspacket. *Thismustcontainatleastonebyteof *data. *@param[in]Fs<tt>opus_int32</tt>:SamplingrateinHz. *Thismustbeamultipleof400,or *inaccurateresultswillbereturned. *@returnsNumberofsamplesperframe.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_samples_per_frame(constunsignedchar *data, opus_int32 Fs) OPUS_ARG_NONNULL(1);
/** Gets the number of channels from an Opus packet. *@param[in]data<tt>char*</tt>:Opuspacket *@returnsNumberofchannels *@retvalOPUS_INVALID_PACKETThecompresseddatapassediscorruptedorofanunsupportedtype
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_channels(constunsignedchar *data) OPUS_ARG_NONNULL(1);
/** Gets the number of frames in an Opus packet. *@param[in]packet<tt>char*</tt>:Opuspacket *@param[in]len<tt>opus_int32</tt>:Lengthofpacket *@returnsNumberofframes *@retvalOPUS_BAD_ARGInsufficientdatawaspassedtothefunction *@retvalOPUS_INVALID_PACKETThecompresseddatapassediscorruptedorofanunsupportedtype
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_frames(constunsignedcharpacket[], opus_int32 len) OPUS_ARG_NONNULL(1);
/** Gets the number of samples of an Opus packet. *@param[in]packet<tt>char*</tt>:Opuspacket *@param[in]len<tt>opus_int32</tt>:Lengthofpacket *@param[in]Fs<tt>opus_int32</tt>:SamplingrateinHz. *Thismustbeamultipleof400,or *inaccurateresultswillbereturned. *@returnsNumberofsamples *@retvalOPUS_BAD_ARGInsufficientdatawaspassedtothefunction *@retvalOPUS_INVALID_PACKETThecompresseddatapassediscorruptedorofanunsupportedtype
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_samples(constunsignedchar packet[], opus_int32 len, opus_int32 Fs) OPUS_ARG_NONNULL(1);
/** Checks whether an Opus packet has LBRR. *@param[in]packet<tt>char*</tt>:Opuspacket *@param[in]len<tt>opus_int32</tt>:Lengthofpacket *@returns1isLBRRispresent,0otherwise *@retvalOPUS_INVALID_PACKETThecompresseddatapassediscorruptedorofanunsupportedtype
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_has_lbrr(constunsignedchar packet[], opus_int32 len);
/** Gets the number of samples of an Opus packet. *@param[in]dec<tt>OpusDecoder*</tt>:Decoderstate *@param[in]packet<tt>char*</tt>:Opuspacket *@param[in]len<tt>opus_int32</tt>:Lengthofpacket *@returnsNumberofsamples *@retvalOPUS_BAD_ARGInsufficientdatawaspassedtothefunction *@retvalOPUS_INVALID_PACKETThecompresseddatapassediscorruptedorofanunsupportedtype
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_nb_samples(const OpusDecoder *dec, constunsignedchar packet[], opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2);
/** Applies soft-clipping to bring a float signal within the [-1,1] range. If *thesignalisalreadyinthatrange,nothingisdone.Iftherearevalues *outsideof[-1,1],thenthesignalisclippedassmoothlyaspossibleto *bothfitintherangeandavoidcreatingexcessivedistortioninthe *process. *@param[in,out]pcm<tt>float*</tt>:InputPCMandmodifiedPCM *@param[in]frame_size<tt>int</tt>Numberofsamplesperchanneltoprocess *@param[in]channels<tt>int</tt>:Numberofchannels *@param[in,out]softclip_mem<tt>float*</tt>:Statememoryforthesoftclippingprocess(onefloatperchannel,initializedtozero)
*/
OPUS_EXPORT void opus_pcm_soft_clip(float *pcm, int frame_size, int channels, float *softclip_mem);
/**@}*/
/** @defgroup opus_repacketizer Repacketizer *@{ * *TherepacketizercanbeusedtomergemultipleOpuspacketsintoasingle *packetoralternativelytosplitOpuspacketsthathavepreviouslybeen *merged.SplittingvalidOpuspacketsisalwaysguaranteedtosucceed, *whereasmergingvalidpacketsonlysucceedsifallframeshavethesame *mode,bandwidth,andframesize,andwhenthetotaldurationofthemerged *packetisnomorethan120ms.The120mslimitcomesfromthe *specificationandlimitsdecodermemoryrequirementsatapointwhere *framingoverheadbecomesnegligible. * *TherepacketizercurrentlyonlyoperatesonelementaryOpus *streams.Itwillnotmanipulatemultistreampacketssuccessfully,exceptin *thedegeneratecasewheretheyconsistofdatafromasinglestream. * *Therepacketizingprocessstartswithcreatingarepacketizerstate,either *bycallingopus_repacketizer_create()orbyallocatingthememoryyourself, *e.g., *@code *OpusRepacketizer*rp; *rp=(OpusRepacketizer*)malloc(opus_repacketizer_get_size()); *if(rp!=NULL) *opus_repacketizer_init(rp); *@endcode * *Thentheapplicationshouldsubmitpacketswithopus_repacketizer_cat(), *extractnewpacketswithopus_repacketizer_out()or *opus_repacketizer_out_range(),andthenresetthestateforthenextsetof *inputpacketsviaopus_repacketizer_init(). * *Forexample,tosplitasequenceofpacketsintoindividualframes: *@code *unsignedchar*data; *intlen; *while(get_next_packet(&data,&len)) *{ *unsignedcharout[1276]; *opus_int32out_len; *intnb_frames; *interr; *inti; *err=opus_repacketizer_cat(rp,data,len); *if(err!=OPUS_OK) *{ *release_packet(data); *returnerr; *} *nb_frames=opus_repacketizer_get_nb_frames(rp); *for(i=0;i<nb_frames;i++) *{ *out_len=opus_repacketizer_out_range(rp,i,i+1,out,sizeof(out)); *if(out_len<0) *{ *release_packet(data); *return(int)out_len; *} *output_next_packet(out,out_len); *} *opus_repacketizer_init(rp); *release_packet(data); *} *@endcode * *Alternatively,tocombineasequenceofframesintopacketsthateach *containupto<code>TARGET_DURATION_MS</code>millisecondsofdata: *@code *// The maximum number of packets with duration TARGET_DURATION_MS occurs *// when the frame size is 2.5 ms, for a total of (TARGET_DURATION_MS*2/5) *// packets. *unsignedchar*data[(TARGET_DURATION_MS*2/5)+1]; *opus_int32len[(TARGET_DURATION_MS*2/5)+1]; *intnb_packets; *unsignedcharout[1277*(TARGET_DURATION_MS*2/2)]; *opus_int32out_len; *intprev_toc; *nb_packets=0; *while(get_next_packet(data+nb_packets,len+nb_packets)) *{ *intnb_frames; *interr; *nb_frames=opus_packet_get_nb_frames(data[nb_packets],len[nb_packets]); *if(nb_frames<1) *{ *release_packets(data,nb_packets+1); *returnnb_frames; *} *nb_frames+=opus_repacketizer_get_nb_frames(rp); *// If adding the next packet would exceed our target, or it has an *// incompatible TOC sequence, output the packets we already have before *// submitting it. *// N.B., The nb_packets > 0 check ensures we've submitted at least one *// packet since the last call to opus_repacketizer_init(). Otherwise a *// single packet longer than TARGET_DURATION_MS would cause us to try to *// output an (invalid) empty packet. It also ensures that prev_toc has *// been set to a valid value. Additionally, len[nb_packets] > 0 is *// guaranteed by the call to opus_packet_get_nb_frames() above, so the *// reference to data[nb_packets][0] should be valid. *if(nb_packets>0&&( *((prev_toc&0xFC)!=(data[nb_packets][0]&0xFC))|| *opus_packet_get_samples_per_frame(data[nb_packets],48000)*nb_frames> *TARGET_DURATION_MS*48)) *{ *out_len=opus_repacketizer_out(rp,out,sizeof(out)); *if(out_len<0) *{ *release_packets(data,nb_packets+1); *return(int)out_len; *} *output_next_packet(out,out_len); *opus_repacketizer_init(rp); *release_packets(data,nb_packets); *data[0]=data[nb_packets]; *len[0]=len[nb_packets]; *nb_packets=0; *} *err=opus_repacketizer_cat(rp,data[nb_packets],len[nb_packets]); *if(err!=OPUS_OK) *{ *release_packets(data,nb_packets+1); *returnerr; *} *prev_toc=data[nb_packets][0]; *nb_packets++; *} *// Output the final, partial packet. *if(nb_packets>0) *{ *out_len=opus_repacketizer_out(rp,out,sizeof(out)); *release_packets(data,nb_packets); *if(out_len<0) *return(int)out_len; *output_next_packet(out,out_len); *} *@endcode * *Analternatewayofmergingpacketsistosimplycallopus_repacketizer_cat() *unconditionallyuntilitfails.Atthatpoint,themergedpacketcanbe *obtainedwithopus_repacketizer_out()andtheinputpacketforwhich *opus_repacketizer_cat()needstobere-addedtoanewlyreinitialized *repacketizerstate.
*/
typedefstruct OpusRepacketizer OpusRepacketizer;
/** Gets the size of an <code>OpusRepacketizer</code> structure. *@returnsThesizeinbytes.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_size(void);
/** Allocates memory and initializes the new repacketizer with *opus_repacketizer_init().
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusRepacketizer *opus_repacketizer_create(void);
/** Frees an <code>OpusRepacketizer</code> allocated by *opus_repacketizer_create(). *@param[in]rp<tt>OpusRepacketizer*</tt>:Statetobefreed.
*/
OPUS_EXPORT void opus_repacketizer_destroy(OpusRepacketizer *rp);
/** Construct a new packet from data previously submitted to the repacketizer *stateviaopus_repacketizer_cat(). *@paramrp<tt>OpusRepacketizer*</tt>:Therepacketizerstatefromwhichto *constructthenewpacket. *@parambegin<tt>int</tt>:Theindexofthefirstframeinthecurrent *repacketizerstatetoincludeintheoutput. *@paramend<tt>int</tt>:Onepasttheindexofthelastframeinthe *currentrepacketizerstatetoincludeinthe *output. *@param[out]data<tt>constunsignedchar*</tt>:Thebufferinwhichto *storetheoutputpacket. *@parammaxlen<tt>opus_int32</tt>:Themaximumnumberofbytestostorein *theoutputbuffer.Inordertoguarantee *success,thisshouldbeatleast *<code>1276</code>forasingleframe, *orformultipleframes, *<code>1277*(end-begin)</code>. *However,<code>1*(end-begin)</code>plus *thesizeofallpacketdatasubmittedto *therepacketizersincethelastcallto *opus_repacketizer_init()or *opus_repacketizer_create()isalso *sufficient,andpossiblymuchsmaller. *@returnsThetotalsizeoftheoutputpacketonsuccess,oranerrorcode *onfailure. *@retval#OPUS_BAD_ARG<code>[begin,end)</code>wasaninvalidrangeof *frames(begin<0,begin>=end,orend> *opus_repacketizer_get_nb_frames()). *@retval#OPUS_BUFFER_TOO_SMALL\amaxlenwasinsufficienttocontainthe *completeoutputpacket.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsignedchar *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Return the total number of frames contained in packet data submitted to *therepacketizerstatesofarviaopus_repacketizer_cat()sincethelast *calltoopus_repacketizer_init()oropus_repacketizer_create(). *Thisdefinesthevalidrangeofpacketsthatcanbeextractedwith *opus_repacketizer_out_range()oropus_repacketizer_out(). *@paramrp<tt>OpusRepacketizer*</tt>:Therepacketizerstatecontainingthe *frames. *@returnsThetotalnumberofframescontainedinthepacketdatasubmitted *totherepacketizerstate.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1);
/** Construct a new packet from data previously submitted to the repacketizer *stateviaopus_repacketizer_cat(). *Thisisaconvenienceroutinethatreturnsallthedatasubmittedsofar *inasinglepacket. *Itisequivalenttocalling *@code *opus_repacketizer_out_range(rp,0,opus_repacketizer_get_nb_frames(rp), *data,maxlen) *@endcode *@paramrp<tt>OpusRepacketizer*</tt>:Therepacketizerstatefromwhichto *constructthenewpacket. *@param[out]data<tt>constunsignedchar*</tt>:Thebufferinwhichto *storetheoutputpacket. *@parammaxlen<tt>opus_int32</tt>:Themaximumnumberofbytestostorein *theoutputbuffer.Inordertoguarantee *success,thisshouldbeatleast *<code>1277*opus_repacketizer_get_nb_frames(rp)</code>. *However, *<code>1*opus_repacketizer_get_nb_frames(rp)</code> *plusthesizeofallpacketdata *submittedtotherepacketizersincethe *lastcalltoopus_repacketizer_init()or *opus_repacketizer_create()isalso *sufficient,andpossiblymuchsmaller. *@returnsThetotalsizeoftheoutputpacketonsuccess,oranerrorcode *onfailure. *@retval#OPUS_BUFFER_TOO_SMALL\amaxlenwasinsufficienttocontainthe *completeoutputpacket.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsignedchar *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1);
/** Pads a given Opus packet to a larger size (possibly changing the TOC sequence). *@param[in,out]data<tt>constunsignedchar*</tt>:Thebuffercontainingthe *packettopad. *@paramlen<tt>opus_int32</tt>:Thesizeofthepacket. *Thismustbeatleast1. *@paramnew_len<tt>opus_int32</tt>:Thedesiredsizeofthepacketafterpadding. *Thismustbeatleastaslargeaslen. *@returnsanerrorcode *@retval#OPUS_OK\aonsuccess. *@retval#OPUS_BAD_ARG\alenwaslessthan1ornew_lenwaslessthanlen. *@retval#OPUS_INVALID_PACKET\adatadidnotcontainavalidOpuspacket.
*/
OPUS_EXPORT int opus_packet_pad(unsignedchar *data, opus_int32 len, opus_int32 new_len);
/** Remove all padding from a given Opus packet and rewrite the TOC sequence to *minimizespaceusage. *@param[in,out]data<tt>constunsignedchar*</tt>:Thebuffercontainingthe *packettostrip. *@paramlen<tt>opus_int32</tt>:Thesizeofthepacket. *Thismustbeatleast1. *@returnsThenewsizeoftheoutputpacketonsuccess,oranerrorcode *onfailure. *@retval#OPUS_BAD_ARG\alenwaslessthan1. *@retval#OPUS_INVALID_PACKET\adatadidnotcontainavalidOpuspacket.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_packet_unpad(unsignedchar *data, opus_int32 len);
/** Pads a given Opus multi-stream packet to a larger size (possibly changing the TOC sequence). *@param[in,out]data<tt>constunsignedchar*</tt>:Thebuffercontainingthe *packettopad. *@paramlen<tt>opus_int32</tt>:Thesizeofthepacket. *Thismustbeatleast1. *@paramnew_len<tt>opus_int32</tt>:Thedesiredsizeofthepacketafterpadding. *Thismustbeatleast1. *@paramnb_streams<tt>opus_int32</tt>:Thenumberofstreams(notchannels)inthepacket. *Thismustbeatleastaslargeaslen. *@returnsanerrorcode *@retval#OPUS_OK\aonsuccess. *@retval#OPUS_BAD_ARG\alenwaslessthan1. *@retval#OPUS_INVALID_PACKET\adatadidnotcontainavalidOpuspacket.
*/
OPUS_EXPORT int opus_multistream_packet_pad(unsignedchar *data, opus_int32 len, opus_int32 new_len, int nb_streams);
/** Remove all padding from a given Opus multi-stream packet and rewrite the TOC sequence to *minimizespaceusage. *@param[in,out]data<tt>constunsignedchar*</tt>:Thebuffercontainingthe *packettostrip. *@paramlen<tt>opus_int32</tt>:Thesizeofthepacket. *Thismustbeatleast1. *@paramnb_streams<tt>opus_int32</tt>:Thenumberofstreams(notchannels)inthepacket. *Thismustbeatleast1. *@returnsThenewsizeoftheoutputpacketonsuccess,oranerrorcode *onfailure. *@retval#OPUS_BAD_ARG\alenwaslessthan1ornew_lenwaslessthanlen. *@retval#OPUS_INVALID_PACKET\adatadidnotcontainavalidOpuspacket.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_packet_unpad(unsignedchar *data, opus_int32 len, int nb_streams);
/**@}*/
#ifdef __cplusplus
} #endif
#endif/* OPUS_H */
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.161Bemerkung:
(vorverarbeitet am 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.