File tree Expand file tree Collapse file tree 3 files changed +33
-27
lines changed
Expand file tree Collapse file tree 3 files changed +33
-27
lines changed Original file line number Diff line number Diff line change @@ -96,33 +96,6 @@ AVSampleFormat findBestOutputSampleFormat(const AVCodec& avCodec) {
9696 return avCodec.sample_fmts [0 ];
9797}
9898
99- UniqueAVFrame allocateAVFrame (
100- int numSamples,
101- int sampleRate,
102- int numChannels,
103- AVSampleFormat sampleFormat) {
104- auto avFrame = UniqueAVFrame (av_frame_alloc ());
105- TORCH_CHECK (avFrame != nullptr , " Couldn't allocate AVFrame." );
106-
107- avFrame->nb_samples = numSamples;
108- avFrame->sample_rate = sampleRate;
109- av_channel_layout_default (&avFrame->ch_layout , numChannels);
110- avFrame->format = sampleFormat;
111- auto status = av_frame_get_buffer (avFrame.get (), 0 );
112-
113- TORCH_CHECK (
114- status == AVSUCCESS,
115- " Couldn't allocate avFrame's buffers: " ,
116- getFFMPEGErrorStringFromErrorCode (status));
117-
118- status = av_frame_make_writable (avFrame.get ());
119- TORCH_CHECK (
120- status == AVSUCCESS,
121- " Couldn't make AVFrame writable: " ,
122- getFFMPEGErrorStringFromErrorCode (status));
123- return avFrame;
124- }
125-
12699} // namespace
127100
128101AudioEncoder::~AudioEncoder () {}
Original file line number Diff line number Diff line change @@ -210,6 +210,33 @@ void setChannelLayout(
210210#endif
211211}
212212
213+ UniqueAVFrame allocateAVFrame (
214+ int numSamples,
215+ int sampleRate,
216+ int numChannels,
217+ AVSampleFormat sampleFormat) {
218+ auto avFrame = UniqueAVFrame (av_frame_alloc ());
219+ TORCH_CHECK (avFrame != nullptr , " Couldn't allocate AVFrame." );
220+
221+ avFrame->nb_samples = numSamples;
222+ avFrame->sample_rate = sampleRate;
223+ setDefaultChannelLayout (avFrame, numChannels);
224+ avFrame->format = sampleFormat;
225+ auto status = av_frame_get_buffer (avFrame.get (), 0 );
226+
227+ TORCH_CHECK (
228+ status == AVSUCCESS,
229+ " Couldn't allocate avFrame's buffers: " ,
230+ getFFMPEGErrorStringFromErrorCode (status));
231+
232+ status = av_frame_make_writable (avFrame.get ());
233+ TORCH_CHECK (
234+ status == AVSUCCESS,
235+ " Couldn't make AVFrame writable: " ,
236+ getFFMPEGErrorStringFromErrorCode (status));
237+ return avFrame;
238+ }
239+
213240SwrContext* createSwrContext (
214241 AVSampleFormat srcSampleFormat,
215242 AVSampleFormat outSampleFormat,
Original file line number Diff line number Diff line change @@ -163,6 +163,12 @@ void setChannelLayout(
163163 const UniqueAVFrame& srcAVFrame,
164164 int desiredNumChannels);
165165
166+ UniqueAVFrame allocateAVFrame (
167+ int numSamples,
168+ int sampleRate,
169+ int numChannels,
170+ AVSampleFormat sampleFormat);
171+
166172SwrContext* createSwrContext (
167173 AVSampleFormat srcSampleFormat,
168174 AVSampleFormat desiredSampleFormat,
You can’t perform that action at this time.
0 commit comments