Skip to content

Commit

Permalink
add avprogram_id to streams_changed() callback
Browse files Browse the repository at this point in the history
This is an int to match type with AVProgram.  In mpegts.c, SectionHeader::id is
a uint16_t as ISO/IEC 13818-1:2021 specifies for program_number.

This allows us to ignore stream changes in programs that are not being watched
when there is more than one program.

Regarding the changes to mpeg.c:
Originally from:
dvb/ac3 patches 1, 2, and 3 from Mark Anderson
87795f6

changed in:
Refs #8134. internal dvd player. resolve problem where pcm_s16be audi…
e64371a

change reverted in:
Refs #8134. revert most of [24239]. Anduin withers reported it makes …
a3d6e14

referencing: #8134 (internal dvd player: pcm_s16be improperly detected as pcm_dvd audio codec.) – MythTV
https://code.mythtv.org/trac/ticket/8134

An MPEG Program Stream can only have one program, so FFmpeg does not create an
AVProgram for it.  Thus av_find_program_from_stream() (and therefore
get_current_AVProgram()) will always return nullptr, so avprogram_id will be
ignored.

The calling conventions of functions with "C" and "C++" language linkage are not
necessarily the same; however, in practice they are, so
AvFormatDecoder::streams_changed() could be used directly.  Doing it correctly
still eliminates the use of a friend function and its double declaration at only
the cost of an extra function call, which doesn't matter since streams_changed()
is only called very rarely.
  • Loading branch information
ulmus-scott committed Aug 10, 2024
1 parent f0625bd commit 4ce4353
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mythtv/external/FFmpeg/libavformat/avformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ typedef struct AVFormatContext {

/* Myth addons */
/* mpeg-ts support */
void (*streams_changed)(void*);
void (*streams_changed)(void* stream_change_data, int avprogram_id);
void *stream_change_data;
/* End Myth addons */

Expand Down
2 changes: 1 addition & 1 deletion mythtv/external/FFmpeg/libavformat/mpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ static int mpegps_read_packet(AVFormatContext *s,

/* notify the callback of the change in streams */
if (s->streams_changed) {
s->streams_changed(s->stream_change_data);
s->streams_changed(s->stream_change_data, -1);
}

found:
Expand Down
2 changes: 1 addition & 1 deletion mythtv/external/FFmpeg/libavformat/mpegts-mythtv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2750,7 +2750,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
!is_pmt_equal(prg, &old_program))
{
av_log(ts->stream, AV_LOG_DEBUG, "streams_changed()\n");
ts->stream->streams_changed(ts->stream->stream_change_data);
ts->stream->streams_changed(ts->stream->stream_change_data, h->id);
}
// end MythTV

Expand Down
19 changes: 16 additions & 3 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,19 +883,32 @@ void AvFormatDecoder::InitByteContext(bool forceseek)
.arg(buf_size).arg(streamed).arg(m_ic->pb->seekable).arg(m_ringBuffer->GetReadBufAvail()));
}

extern "C" void HandleStreamChange(void *data)
void AvFormatDecoder::streams_changed(void *data, int avprogram_id)
{
auto *decoder = reinterpret_cast<AvFormatDecoder*>(data);

int cnt = decoder->m_ic->nb_streams;

LOG(VB_PLAYBACK, LOG_INFO, LOC +
QString("streams_changed 0x%1 -- stream count %2")
.arg((uint64_t)data,0,16).arg(cnt));
QString("streams_changed 0x%1 -- program_number %2 stream count %3")
.arg((uint64_t)data,0,16).arg(QString::number(avprogram_id), QString::number(cnt)));

auto* program = decoder->get_current_AVProgram();
if (program != nullptr && program->id != avprogram_id)
{
return;
}
decoder->m_streamsChanged = true;
}

extern "C"
{
static void HandleStreamChange(void *data, int avprogram_id)
{
AvFormatDecoder::streams_changed(data, avprogram_id);
}
}

int AvFormatDecoder::FindStreamInfo(void)
{
m_avCodecLock.lock();
Expand Down
6 changes: 2 additions & 4 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class MythSqlDatabase;

struct SwsContext;

extern "C" void HandleStreamChange(void *data);

class AudioInfo
{
public:
Expand Down Expand Up @@ -81,8 +79,6 @@ class AudioInfo
/// A decoder for media files.
class AvFormatDecoder : public DecoderBase
{
friend void HandleStreamChange(void *data);

public:
AvFormatDecoder(MythPlayer *parent, const ProgramInfo &pginfo,
PlayerFlags flags);
Expand Down Expand Up @@ -178,6 +174,8 @@ class AvFormatDecoder : public DecoderBase

static int GetMaxReferenceFrames(AVCodecContext *Context);

static void streams_changed(void *data, int avprogram_id);

protected:
int AutoSelectTrack(uint type) override; // DecoderBase
void ScanATSCCaptionStreams(int av_index);
Expand Down

0 comments on commit 4ce4353

Please sign in to comment.