Skip to content

Commit 79c84c6

Browse files
committed
Move device interface from stream to decoder
Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
1 parent 32d9598 commit 79c84c6

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/torchcodec/_core/SingleStreamDecoder.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ void SingleStreamDecoder::addStream(
405405
streamInfo.timeBase = formatContext_->streams[activeStreamIndex_]->time_base;
406406
streamInfo.stream = formatContext_->streams[activeStreamIndex_];
407407
streamInfo.avMediaType = mediaType;
408-
streamInfo.deviceInterface = createDeviceInterface(device);
408+
409+
deviceInterface = createDeviceInterface(device);
409410

410411
// This should never happen, checking just to be safe.
411412
TORCH_CHECK(
@@ -417,10 +418,9 @@ void SingleStreamDecoder::addStream(
417418
// TODO_CODE_QUALITY it's pretty meh to have a video-specific logic within
418419
// addStream() which is supposed to be generic
419420
if (mediaType == AVMEDIA_TYPE_VIDEO) {
420-
if (streamInfo.deviceInterface) {
421+
if (deviceInterface) {
421422
avCodec = makeAVCodecOnlyUseForCallingAVFindBestStream(
422-
streamInfo.deviceInterface
423-
->findCodec(streamInfo.stream->codecpar->codec_id)
423+
deviceInterface->findCodec(streamInfo.stream->codecpar->codec_id)
424424
.value_or(avCodec));
425425
}
426426
}
@@ -438,8 +438,8 @@ void SingleStreamDecoder::addStream(
438438

439439
// TODO_CODE_QUALITY same as above.
440440
if (mediaType == AVMEDIA_TYPE_VIDEO) {
441-
if (streamInfo.deviceInterface) {
442-
streamInfo.deviceInterface->initializeContext(codecContext);
441+
if (deviceInterface) {
442+
deviceInterface->initializeContext(codecContext);
443443
}
444444
}
445445

@@ -1210,11 +1210,11 @@ SingleStreamDecoder::convertAVFrameToFrameOutput(
12101210
formatContext_->streams[activeStreamIndex_]->time_base);
12111211
if (streamInfo.avMediaType == AVMEDIA_TYPE_AUDIO) {
12121212
convertAudioAVFrameToFrameOutputOnCPU(avFrame, frameOutput);
1213-
} else if (!streamInfo.deviceInterface) {
1213+
} else if (!deviceInterface) {
12141214
convertAVFrameToFrameOutputOnCPU(
12151215
avFrame, frameOutput, preAllocatedOutputTensor);
1216-
} else if (streamInfo.deviceInterface) {
1217-
streamInfo.deviceInterface->convertAVFrameToFrameOutput(
1216+
} else if (deviceInterface) {
1217+
deviceInterface->convertAVFrameToFrameOutput(
12181218
streamInfo.videoStreamOptions,
12191219
avFrame,
12201220
frameOutput,

src/torchcodec/_core/SingleStreamDecoder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,6 @@ class SingleStreamDecoder {
356356
// Used to know whether a new FilterGraphContext or UniqueSwsContext should
357357
// be created before decoding a new frame.
358358
DecodedFrameContext prevFrameContext;
359-
360-
std::unique_ptr<DeviceInterface> deviceInterface;
361359
};
362360

363361
// --------------------------------------------------------------------------
@@ -494,6 +492,7 @@ class SingleStreamDecoder {
494492
SeekMode seekMode_;
495493
ContainerMetadata containerMetadata_;
496494
UniqueDecodingAVFormatContext formatContext_;
495+
std::unique_ptr<DeviceInterface> deviceInterface;
497496
std::map<int, StreamInfo> streamInfos_;
498497
const int NO_ACTIVE_STREAM = -2;
499498
int activeStreamIndex_ = NO_ACTIVE_STREAM;

0 commit comments

Comments
 (0)