Skip to content

Commit

Permalink
Caption language query improvements.
Browse files Browse the repository at this point in the history
 Adds GetCaptionLanguage() which allows you to query the caption language by type and ID.
 Uses GetCaptionLanguage() to guess at the language of an unspecified CC1 or CC3 stream by using the service 1 and service 2 languages (In practice the CC1 and CC3 are in the same lanuage as service 1 and service 2, especially when they are not described in the caption descriptor.)
  • Loading branch information
daniel-kristjansson committed Nov 18, 2011
1 parent 025670e commit 3341f2c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
53 changes: 45 additions & 8 deletions mythtv/libs/libmythtv/avformatdecoder.cpp
Expand Up @@ -2212,6 +2212,7 @@ void AvFormatDecoder::DoFastForwardSeek(long long desiredFrame, bool &needflush)
return;
}

/// Returns DVD Subtitle language
int AvFormatDecoder::GetSubtitleLanguage(uint subtitle_index, uint stream_index)
{
(void)subtitle_index;
Expand All @@ -2222,6 +2223,35 @@ int AvFormatDecoder::GetSubtitleLanguage(uint subtitle_index, uint stream_index)
iso639_str3_to_key("und");
}

/// Return ATSC Closed Caption Language
int AvFormatDecoder::GetCaptionLanguage(TrackTypes trackType, int service_num)
{
int ret = -1;
for (uint i = 0; i < (uint) pmt_track_types.size(); i++)
{
if ((pmt_track_types[i] == trackType) &&
(pmt_tracks[i].stream_id == service_num))
{
ret = pmt_tracks[i].language;
if (!iso639_is_key_undefined(ret))
return ret;
}
}

for (uint i = 0; i < (uint) stream_track_types.size(); i++)
{
if ((stream_track_types[i] == trackType) &&
(stream_tracks[i].stream_id == service_num))
{
ret = stream_tracks[i].language;
if (!iso639_is_key_undefined(ret))
return ret;
}
}

return ret;
}

int AvFormatDecoder::GetAudioLanguage(uint audio_index, uint stream_index)
{
return GetSubtitleLanguage(audio_index, stream_index);
Expand Down Expand Up @@ -2614,24 +2644,31 @@ void AvFormatDecoder::UpdateCaptionTracksFromStreams(
stream_track_types.clear();
int av_index = selectedTrack[kTrackTypeVideo].av_stream_index;
int lang = iso639_str3_to_key("und");
for (uint i = 0; i < 4; i++)
for (uint i = 1; i < 64; i++)
{
if (seen_608[i])
if (seen_708[i] && !ccX08_in_pmt[i+4])
{
StreamInfo si(av_index, lang, 0/*lang_idx*/,
i+1, false/*easy*/, false/*wide*/);
i, false/*easy*/, true/*wide*/);
stream_tracks.push_back(si);
stream_track_types.push_back(kTrackTypeCC608);
stream_track_types.push_back(kTrackTypeCC708);
}
}
for (uint i = 1; i < 64; i++)
for (uint i = 0; i < 4; i++)
{
if (seen_708[i] && !ccX08_in_pmt[i+4])
if (seen_608[i] && !ccX08_in_pmt[i])
{
if (0==i)
lang = GetCaptionLanguage(kTrackTypeCC708, 1);
else if (2==i)
lang = GetCaptionLanguage(kTrackTypeCC708, 2);
else
lang = iso639_str3_to_key("und");

StreamInfo si(av_index, lang, 0/*lang_idx*/,
i, false/*easy*/, true/*wide*/);
i+1, false/*easy*/, false/*wide*/);
stream_tracks.push_back(si);
stream_track_types.push_back(kTrackTypeCC708);
stream_track_types.push_back(kTrackTypeCC608);
}
}
UpdateATSCCaptionTracks();
Expand Down
7 changes: 5 additions & 2 deletions mythtv/libs/libmythtv/avformatdecoder.h
Expand Up @@ -176,6 +176,11 @@ class AvFormatDecoder : public DecoderBase
virtual bool SetAudioByComponentTag(int tag);
virtual bool SetVideoByComponentTag(int tag);

// Stream language info
virtual int GetSubtitleLanguage(uint subtitle_index, uint stream_index);
virtual int GetCaptionLanguage(TrackTypes trackType, int service_num);
virtual int GetAudioLanguage(uint audio_index, uint stream_index);

protected:
RingBuffer *getRingBuf(void) { return ringBuffer; }

Expand Down Expand Up @@ -250,8 +255,6 @@ class AvFormatDecoder : public DecoderBase
virtual void DoFastForwardSeek(long long desiredFrame, bool &needflush);
virtual void StreamChangeCheck(void) { }
virtual void PostProcessTracks(void) { }
virtual int GetSubtitleLanguage(uint subtitle_index, uint stream_index);
virtual int GetAudioLanguage(uint audio_index, uint stream_index);

PrivateDecoder *private_dec;

Expand Down

0 comments on commit 3341f2c

Please sign in to comment.