Skip to content

Commit dd85e96

Browse files
committed
Add comments
1 parent 7d643f2 commit dd85e96

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/torchcodec/_core/Encoder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ void AudioEncoder::initializeEncoder(
179179

180180
desiredNumChannels_ = static_cast<int>(numChannels.value_or(wf_.sizes()[0]));
181181
validateNumChannels(*avCodec, desiredNumChannels_);
182+
// The avCodecContext layout defines the layout of the encoded output, it's
183+
// not related to the input sampes.
182184
setDefaultChannelLayout(avCodecContext_, desiredNumChannels_);
183185

184186
validateSampleRate(*avCodec, sampleRate);
@@ -233,6 +235,8 @@ void AudioEncoder::encode() {
233235
avFrame->format = AV_SAMPLE_FMT_FLTP;
234236
avFrame->sample_rate = avCodecContext_->sample_rate;
235237
avFrame->pts = 0;
238+
// We set the channel layout of the frame to the default layout corresponding
239+
// to the input samples' number of channels
236240
setDefaultChannelLayout(avFrame, static_cast<int>(wf_.sizes()[0]));
237241

238242
auto status = av_frame_get_buffer(avFrame.get(), 0);

src/torchcodec/_core/FFMPEGCommon.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ void validateNumChannels(const AVCodec& avCodec, int numChannels) {
113113
return;
114114
}
115115
}
116+
// At this point it seems that the encoder doesn't support the requested
117+
// number of channels, so we error out.
116118
std::stringstream supportedNumChannels;
117119
for (auto i = 0; avCodec.ch_layouts[i].order != AV_CHANNEL_ORDER_UNSPEC;
118120
++i) {
@@ -126,6 +128,8 @@ void validateNumChannels(const AVCodec& avCodec, int numChannels) {
126128
// can't validate, same as above.
127129
return;
128130
}
131+
// At this point it seems that the encoder doesn't support the requested
132+
// number of channels, so we error out.
129133
for (auto i = 0; avCodec.channel_layouts[i] != 0; ++i) {
130134
if (numChannels ==
131135
av_get_channel_layout_nb_channels(avCodec.channel_layouts[i])) {

0 commit comments

Comments
 (0)