-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove use of AVCodecPtr in interface definition #453
Changes from 3 commits
db9bed0
74aef5b
4ccb307
7b3be11
6be8abc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -426,7 +426,7 @@ void VideoDecoder::createFilterGraph( | |
} | ||
|
||
int VideoDecoder::getBestStreamIndex(AVMediaType mediaType) { | ||
AVCodecPtr codec = nullptr; | ||
AVCodecPtrBestStream codec = nullptr; | ||
int streamNumber = | ||
av_find_best_stream(formatContext_.get(), mediaType, -1, -1, &codec, 0); | ||
return streamNumber; | ||
|
@@ -441,7 +441,7 @@ void VideoDecoder::addVideoStreamDecoder( | |
" is already active."); | ||
} | ||
TORCH_CHECK(formatContext_.get() != nullptr); | ||
AVCodecPtr codec = nullptr; | ||
AVCodecPtrBestStream codec = nullptr; | ||
int streamNumber = av_find_best_stream( | ||
formatContext_.get(), | ||
AVMEDIA_TYPE_VIDEO, | ||
|
@@ -464,8 +464,9 @@ void VideoDecoder::addVideoStreamDecoder( | |
} | ||
|
||
if (options.device.type() == torch::kCUDA) { | ||
codec = findCudaCodec(options.device, streamInfo.stream->codecpar->codec_id) | ||
.value_or(codec); | ||
codec = makeAVCodecPtrBestStream( | ||
findCudaCodec(options.device, streamInfo.stream->codecpar->codec_id) | ||
.value_or(codec)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to check my understanding: the main point of this PR is that previously, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, no, previously |
||
} | ||
|
||
AVCodecContext* codecContext = avcodec_alloc_context3(codec); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fear that the name
AVCodecPtrBestStream
may lead to some confusion. It's true that we only use it when interacting withav_find_best_stream
, but weirdly enough,av_find_best_stream
's purpose isn't just to automatically detect the "best" stream (in the sense that we would normally think about it).We pass
preferredStreamNumber
toav_find_best_stream
, andav_find_best_stream
will only run its "find the best stream" heuristic whenpreferredStreamNumber
is -1. When we call it with e.g. 3, it will return the stream with index 3 (which may not be the "best" stream). SoAVCodecPtrBestStream
isn't necessarily the codec of the best stream either.(docs and source)
Note: While the
av_find_best_stream
name is a bit misleading, I think we should still call it, perhaps with a comment to disambiguate.: internally it does some work that we would have to be doing manually if we didn't call it, particularly it sets thecodec
value by callingavcodec_find_decoder()
.I'm curious to learn more about the concern here. My current understanding (as per my other comment) is that we want to avoid implicit casts, so maybe keeping the existing
AVCodecPtr
name is OK - but I might be missing something?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intention is to rename
AVCodecPtr
to what is morallyAVCodecPtrOnlyUseThisTypeWhenCallingAVFormatBestStream
. Hence I appendedBestStream
; my intention was not to say "This is the codec for the best stream," but rather "This is theAVCodec
pointer type to use when callingav_find_best_stream()
."My concern, which is kinda what happened, is that
AVCodecPtr
looks general enough that someone will want to use it as a general "I need a pointer to anAVCodec
" type. But it's not that. It's a type which allows us to dance around the awkwardness that the functionav_find_best_stream()
had a breaking API change after version 4.Implicit casts aren't a problem, per se - the compiler will prevent them. The problem is overuse of
AVCodecPtr
. I want to give it an ugly name that is awkward to use to indicate that it's not a general type.