mirror of
https://github.com/tuxbox-neutrino/libstb-hal.git
synced 2025-08-27 07:23:11 +02:00
libeplayer3: work around duplicate ffmpeg stream ids by comparing stream addresses instead of pids (plus a couple of optimizations)
This commit is contained in:
@@ -60,7 +60,7 @@ Input::~Input()
|
||||
int64_t calcPts(AVFormatContext *avfc, AVStream * stream, int64_t pts)
|
||||
{
|
||||
if (!avfc || !stream) {
|
||||
fprintf(stderr, "player / stream null\n");
|
||||
fprintf(stderr, "context / stream null\n");
|
||||
return INVALID_PTS_VALUE;
|
||||
}
|
||||
|
||||
@@ -168,6 +168,7 @@ bool Input::Play()
|
||||
for (i = 0; i < avfc->nb_streams; i++)
|
||||
if (avfc->streams[i]->codec && avfc->streams[i]->codec->codec)
|
||||
avcodec_flush_buffers(avfc->streams[i]->codec);
|
||||
player->output.ClearVideo();
|
||||
}
|
||||
|
||||
AVPacket packet;
|
||||
@@ -183,14 +184,13 @@ bool Input::Play()
|
||||
|
||||
player->readCount += packet.size;
|
||||
|
||||
int pid = avfc->streams[packet.stream_index]->id;
|
||||
|
||||
AVStream *stream = avfc->streams[packet.stream_index];
|
||||
Track *_videoTrack = videoTrack;
|
||||
Track *_audioTrack = audioTrack;
|
||||
Track *_subtitleTrack = subtitleTrack;
|
||||
Track *_teletextTrack = teletextTrack;
|
||||
|
||||
if (_videoTrack && (_videoTrack->pid == pid)) {
|
||||
if (_videoTrack && (_videoTrack->stream == stream)) {
|
||||
int64_t pts = calcPts(avfc, _videoTrack->stream, packet.pts);
|
||||
if (!player->output.Write(avfc, _videoTrack->stream, &packet, pts)) {
|
||||
if (warnVideoWrite)
|
||||
@@ -200,7 +200,7 @@ bool Input::Play()
|
||||
warnVideoWrite = 100;
|
||||
}
|
||||
}
|
||||
} else if (_audioTrack && (_audioTrack->pid == pid)) {
|
||||
} else if (_audioTrack && (_audioTrack->stream == stream)) {
|
||||
if (restart_audio_resampling) {
|
||||
restart_audio_resampling = false;
|
||||
player->output.Write(avfc, _audioTrack->stream, NULL, 0);
|
||||
@@ -216,7 +216,7 @@ bool Input::Play()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (_subtitleTrack && (_subtitleTrack->pid == pid)) {
|
||||
} else if (_subtitleTrack && (_subtitleTrack->stream == stream)) {
|
||||
if (((AVStream *) _subtitleTrack->stream)->codec->codec) {
|
||||
AVSubtitle sub;
|
||||
memset(&sub, 0, sizeof(sub));
|
||||
@@ -229,7 +229,7 @@ bool Input::Play()
|
||||
switch (sub.rects[0]->type) {
|
||||
case SUBTITLE_TEXT: // FIXME?
|
||||
case SUBTITLE_ASS:
|
||||
dvbsub_ass_write(((AVStream *) _subtitleTrack->stream)->codec, &sub, pid);
|
||||
dvbsub_ass_write(_subtitleTrack->stream->codec, &sub, _subtitleTrack->stream->id);
|
||||
break;
|
||||
case SUBTITLE_BITMAP: {
|
||||
int64_t pts = calcPts(avfc, _subtitleTrack->stream, packet.pts);
|
||||
@@ -242,8 +242,8 @@ bool Input::Play()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (_teletextTrack && (_teletextTrack->pid == pid)) {
|
||||
teletext_write(pid, packet.data, packet.size);
|
||||
} else if (_teletextTrack && (_teletextTrack->stream == stream)) {
|
||||
teletext_write(_teletextTrack->stream->id, packet.data, packet.size);
|
||||
}
|
||||
|
||||
av_free_packet(&packet);
|
||||
|
@@ -128,6 +128,7 @@ bool Output::Play()
|
||||
|
||||
if (videoStream && videofd > -1) {
|
||||
videoWriter = Writer::GetWriter(videoStream->codec->codec_id, videoStream->codec->codec_type);
|
||||
videoWriter->Init();
|
||||
if (dioctl(videofd, VIDEO_SET_ENCODING, videoWriter->GetVideoEncoding(videoStream->codec->codec_id))
|
||||
|| dioctl(videofd, VIDEO_PLAY, NULL))
|
||||
ret = false;
|
||||
@@ -135,6 +136,7 @@ bool Output::Play()
|
||||
|
||||
if (audioStream && audiofd > -1) {
|
||||
audioWriter = Writer::GetWriter(audioStream->codec->codec_id, audioStream->codec->codec_type);
|
||||
audioWriter->Init();
|
||||
if (dioctl(audiofd, AUDIO_SET_ENCODING, audioWriter->GetAudioEncoding(audioStream->codec->codec_id))
|
||||
|| dioctl(audiofd, AUDIO_PLAY, NULL))
|
||||
ret = false;
|
||||
|
@@ -72,10 +72,7 @@ bool Player::Open(const char *Url, bool _noprobe)
|
||||
|
||||
manager.clearTracks();
|
||||
|
||||
if (*Url == '/') {
|
||||
url = "file://";
|
||||
url += Url;
|
||||
} else if (!strncmp("mms://", Url, 6)) {
|
||||
if (!strncmp("mms://", Url, 6)) {
|
||||
url = "mmst";
|
||||
url += Url + 3;
|
||||
isHttp = true;
|
||||
@@ -207,7 +204,6 @@ bool Player::Stop()
|
||||
bool ret = true;
|
||||
|
||||
if (isPlaying) {
|
||||
|
||||
isPaused = false;
|
||||
isPlaying = false;
|
||||
isForwarding = false;
|
||||
|
@@ -54,16 +54,14 @@ bool WriterDIVX::Write(int fd, AVFormatContext * /* avfc */, AVStream *stream, A
|
||||
return false;
|
||||
|
||||
uint8_t PesHeader[PES_MAX_HEADER_SIZE];
|
||||
uint8_t FakeHeaders[64]; // 64bytes should be enough to make the fake headers
|
||||
uint8_t FakeHeaders[64] = { 0 }; // 64bytes should be enough to make the fake headers
|
||||
unsigned int FakeHeaderLength;
|
||||
uint8_t Version = 5;
|
||||
unsigned int FakeStartCode = (Version << 8) | PES_VERSION_FAKE_START_CODE;
|
||||
unsigned int usecPerFrame = 41708; /* Hellmaster1024: default value */
|
||||
BitPacker_t ld = { FakeHeaders, 0, 32 };
|
||||
|
||||
usecPerFrame = 1000000 / av_q2d(stream->r_frame_rate);
|
||||
|
||||
memset(FakeHeaders, 0, sizeof(FakeHeaders));
|
||||
usecPerFrame = 1000000.0 / av_q2d(stream->r_frame_rate);
|
||||
|
||||
/* Create info record for frame parser */
|
||||
/* divx4 & 5
|
||||
@@ -75,11 +73,10 @@ bool WriterDIVX::Write(int fd, AVFormatContext * /* avfc */, AVStream *stream, A
|
||||
PutBits(&ld, 0, 8); // profile = reserved
|
||||
PutBits(&ld, 0x1b2, 32); // startcode (user data)
|
||||
PutBits(&ld, 0x53545443, 32); // STTC - an embedded ST timecode from an avi file
|
||||
PutBits(&ld, usecPerFrame, 32);
|
||||
// microseconds per frame
|
||||
PutBits(&ld, usecPerFrame, 32); // microseconds per frame
|
||||
FlushBits(&ld);
|
||||
|
||||
FakeHeaderLength = (ld.Ptr - (FakeHeaders));
|
||||
FakeHeaderLength = (ld.Ptr - FakeHeaders);
|
||||
|
||||
struct iovec iov[4];
|
||||
int ic = 0;
|
||||
|
@@ -38,9 +38,9 @@ void PutBits(BitPacker_t * ld, unsigned int code, unsigned int length)
|
||||
|
||||
#ifdef DEBUG_PUTBITS
|
||||
if (ld->debug)
|
||||
dprintf("code = %d, length = %d, bit_buf = 0x%x, bit_left = %d\n",
|
||||
code, length, bit_buf, bit_left);
|
||||
#endif /* DEBUG_PUTBITS */
|
||||
dprintf("code = %d, length = %d, bit_buf = 0x%x, bit_left = %d\n",
|
||||
code, length, bit_buf, bit_left);
|
||||
#endif
|
||||
|
||||
if (length < bit_left) {
|
||||
/* fits into current buffer */
|
||||
@@ -50,10 +50,10 @@ void PutBits(BitPacker_t * ld, unsigned int code, unsigned int length)
|
||||
/* doesn't fit */
|
||||
bit_buf <<= bit_left;
|
||||
bit_buf |= code >> (length - bit_left);
|
||||
ld->Ptr[0] = (char) (bit_buf >> 24);
|
||||
ld->Ptr[1] = (char) (bit_buf >> 16);
|
||||
ld->Ptr[2] = (char) (bit_buf >> 8);
|
||||
ld->Ptr[3] = (char) bit_buf;
|
||||
ld->Ptr[0] = (uint8_t) (bit_buf >> 24);
|
||||
ld->Ptr[1] = (uint8_t) (bit_buf >> 16);
|
||||
ld->Ptr[2] = (uint8_t) (bit_buf >> 8);
|
||||
ld->Ptr[3] = (uint8_t) bit_buf;
|
||||
ld->Ptr += 4;
|
||||
length -= bit_left;
|
||||
bit_buf = code & ((1 << length) - 1);
|
||||
@@ -64,7 +64,7 @@ void PutBits(BitPacker_t * ld, unsigned int code, unsigned int length)
|
||||
#ifdef DEBUG_PUTBITS
|
||||
if (ld->debug)
|
||||
dprintf("bit_left = %d, bit_buf = 0x%x\n", bit_left, bit_buf);
|
||||
#endif /* DEBUG_PUTBITS */
|
||||
#endif
|
||||
|
||||
/* writeback */
|
||||
ld->BitBuffer = bit_buf;
|
||||
@@ -78,7 +78,7 @@ void FlushBits(BitPacker_t * ld)
|
||||
#ifdef DEBUG_PUTBITS
|
||||
if (ld->debug)
|
||||
dprintf("flushing 0x%2.2x\n", ld->BitBuffer >> 24);
|
||||
#endif /* DEBUG_PUTBITS */
|
||||
#endif
|
||||
*ld->Ptr++ = ld->BitBuffer >> 24;
|
||||
ld->BitBuffer <<= 8;
|
||||
ld->Remaining += 8;
|
||||
|
Reference in New Issue
Block a user