MythTV master
mythbddecoder.cpp
Go to the documentation of this file.
1// MythTV
4
8
9#define LOC QString("BDDecoder: ")
10
12 : AvFormatDecoder(Parent, PGInfo, Flags)
13{
14}
15
17{
19 return m_ringBuffer->BD()->IsValidStream(static_cast<uint>(StreamId));
20 return AvFormatDecoder::IsValidStream(StreamId);
21}
22
23void MythBDDecoder::Reset(bool ResetVideoData, bool SeekReset, bool ResetFile)
24{
25 AvFormatDecoder::Reset(ResetVideoData, SeekReset, ResetFile);
27}
28
30{
31 if (!m_ringBuffer->IsBD())
32 return;
33
34 auto currentpos = static_cast<long long>(m_ringBuffer->BD()->GetCurrentTime().count() * m_fps);
35 m_framesPlayed = m_framesRead = currentpos ;
36 m_parent->SetFramesPlayed(static_cast<uint64_t>(currentpos + 1));
37}
38
39bool MythBDDecoder::DoRewindSeek(long long DesiredFrame)
40{
41 if (!m_ringBuffer->IsBD())
42 return false;
43
44 m_ringBuffer->Seek(BDFindPosition(DesiredFrame), SEEK_SET);
45 m_framesPlayed = m_framesRead = m_lastKey = DesiredFrame + 1;
46 m_frameCounter += 100;
47 return true;
48}
49
50void MythBDDecoder::DoFastForwardSeek(long long DesiredFrame, bool &Needflush)
51{
52 if (!m_ringBuffer->IsBD())
53 return;
54
55 m_ringBuffer->Seek(BDFindPosition(DesiredFrame), SEEK_SET);
56 Needflush = true;
57 m_framesPlayed = m_framesRead = m_lastKey = DesiredFrame + 1;
58 m_frameCounter += 100;
59}
60
62{
63 if (!m_ringBuffer->IsBD())
64 return;
65
67 {
68 // This was originally in HandleBDStreamChange
69 LOG(VB_PLAYBACK, LOG_INFO, LOC + "resetting");
70 QMutexLocker locker(&m_trackLock);
71 Reset(true, false, false);
73 ScanStreams(false);
74 m_streamsChanged=false;
75 }
76
78 {
82 }
83}
84
85int MythBDDecoder::GetSubtitleLanguage(uint /*SubtitleIndex*/, uint StreamIndex)
86{
87 if (m_ringBuffer && m_ringBuffer->IsBD() && (StreamIndex < m_ic->nb_streams) &&
88 (m_ic->streams[StreamIndex] != nullptr))
89 {
90 return m_ringBuffer->BD()->GetSubtitleLanguage(static_cast<uint>(m_ic->streams[StreamIndex]->id));
91 }
92
93 return iso639_str3_to_key("und");
94}
95
96int MythBDDecoder::GetAudioLanguage(uint /*AudioIndex*/, uint StreamIndex)
97{
98 if (m_ringBuffer && m_ringBuffer->IsBD() && (StreamIndex < m_ic->nb_streams) &&
99 (m_ic->streams[StreamIndex] != nullptr))
100 {
101 return m_ringBuffer->BD()->GetAudioLanguage(static_cast<uint>(m_ic->streams[StreamIndex]->id));
102 }
103
104 return iso639_str3_to_key("und");
105}
106
107int MythBDDecoder::ReadPacket(AVFormatContext *Ctx, AVPacket* Pkt, bool& /*StorePacket*/)
108{
109 m_avCodecLock.lock();
110 int result = av_read_frame(Ctx, Pkt);
111 m_avCodecLock.unlock();
112 /* If we seem to have hit the end of the file, the ringbuffer may
113 * just be blocked in order to drain the ffmpeg buffers, so try
114 * unblocking it and reading again.
115 * If ffmpeg's buffers are empty, it takes a couple of goes to
116 * fill and read from them.
117 */
118 for (int count = 0; (count < 3) && (result == AVERROR_EOF); count++)
119 {
122 m_avCodecLock.lock();
123 result = av_read_frame(Ctx, Pkt);
124 m_avCodecLock.unlock();
125 }
126
127 if (result >= 0)
128 {
129 Pkt->dts = m_ringBuffer->BD()->AdjustTimestamp(Pkt->dts);
130 Pkt->pts = m_ringBuffer->BD()->AdjustTimestamp(Pkt->pts);
131 }
132
133 return result;
134}
135
136long long MythBDDecoder::BDFindPosition(long long DesiredFrame)
137{
138 if (!m_ringBuffer->IsBD())
139 return 0;
140
141 int ffrewSkip = 1;
142 int current_speed = 0;
143 if (m_parent)
144 {
145 ffrewSkip = m_parent->GetFFRewSkip();
146 current_speed = static_cast<int>(m_parent->GetNextPlaySpeed());
147 }
148
149 if (ffrewSkip == 1 || ffrewSkip == 0)
150 {
151#if 0
152 int diffTime = (int)ceil((desiredFrame - m_framesPlayed) / m_fps);
153 long long desiredTimePos = m_ringBuffer->BD()->GetCurrentTime() +
154 diffTime;
155 if (diffTime <= 0)
156 desiredTimePos--;
157 else
158 desiredTimePos++;
159
160 if (desiredTimePos < 0)
161 desiredTimePos = 0;
162#endif
163 return static_cast<long long>(DesiredFrame * 90000.0 / m_fps);
164 }
165 return current_speed;
166}
A decoder for media files.
AVFormatContext * m_ic
void Reset(bool reset_video_data, bool seek_reset, bool reset_file) override
int ScanStreams(bool novideo)
void SeekReset(long long newkey, uint skipFrames, bool doFlush, bool discardFrames) override
QRecursiveMutex m_avCodecLock
virtual bool IsValidStream(int)
uint64_t m_frameCounter
Definition: decoderbase.h:292
double m_fps
Definition: decoderbase.h:282
long long m_framesRead
Definition: decoderbase.h:291
MythMediaBuffer * m_ringBuffer
Definition: decoderbase.h:280
QRecursiveMutex m_trackLock
Definition: decoderbase.h:337
virtual void ResetPosMap(void)
MythPlayer * m_parent
Definition: decoderbase.h:277
virtual bool SyncPositionMap(void)
Updates the position map used for skipping frames.
long long m_lastKey
Definition: decoderbase.h:295
long long m_framesPlayed
Definition: decoderbase.h:290
std::chrono::seconds GetCurrentTime(void) const
bool TitleChanged(void)
bool IsReadingBlocked(void)
int64_t AdjustTimestamp(int64_t Timestamp) const
void UnblockReading(void)
bool IsValidStream(uint StreamId)
int GetAudioLanguage(uint StreamID)
int GetSubtitleLanguage(uint StreamID)
int GetAudioLanguage(uint AudioIndex, uint StreamIndex) override
void DoFastForwardSeek(long long DesiredFrame, bool &Needflush) override
Seeks to the keyframe just before the desiredFrame if exact seeks is enabled, or the frame just after...
int GetSubtitleLanguage(uint SubtitleIndex, uint StreamIndex) override
Returns DVD Subtitle language.
bool DoRewindSeek(long long DesiredFrame) override
long long BDFindPosition(long long DesiredFrame)
void StreamChangeCheck(void) override
MythBDDecoder(MythPlayer *Parent, const ProgramInfo &PGInfo, PlayerFlags Flags)
void Reset(bool ResetVideoData, bool SeekReset, bool ResetFile) override
int ReadPacket(AVFormatContext *Ctx, AVPacket *Pkt, bool &StorePacket) override
void UpdateFramesPlayed(void) override
bool IsValidStream(int StreamId) override
long long Seek(long long Position, int Whence, bool HasLock=false)
const MythBDBuffer * BD(void) const
bool IsBD(void) const
float GetNextPlaySpeed(void) const
Definition: mythplayer.h:140
void SetFramesPlayed(uint64_t played)
Definition: mythplayer.cpp:559
bool AtNormalSpeed(void) const
Definition: mythplayer.h:157
int GetFFRewSkip(void) const
Definition: mythplayer.h:137
Holds information on recordings and videos.
Definition: programinfo.h:68
unsigned int uint
Definition: freesurround.h:24
ISO 639-1 and ISO 639-2 support functions.
static int iso639_str3_to_key(const unsigned char *iso639_2)
Definition: iso639.h:60
#define LOC
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
PlayerFlags
Definition: mythplayer.h:65