Skip to content

Commit

Permalink
Return a more accurate mpeg ringbuffer decode pos.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Jun 8, 2013
1 parent 94cce21 commit 17907b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 10 additions & 4 deletions Core/HW/MediaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ void MediaEngine::closeMedia() {
av_free(m_pFrameRGB);
if (m_pFrame)
av_free(m_pFrame);
if (m_pIOContext && ((AVIOContext*)m_pIOContext)->buffer)
av_free(((AVIOContext*)m_pIOContext)->buffer);
if (m_pIOContext && m_pIOContext->buffer)
av_free(m_pIOContext->buffer);
if (m_pIOContext)
av_free(m_pIOContext);
if (m_pCodecCtx)
Expand Down Expand Up @@ -183,8 +183,8 @@ bool MediaEngine::openContext() {

AVFormatContext *pFormatCtx = avformat_alloc_context();
m_pFormatCtx = (void*)pFormatCtx;
m_pIOContext = (void*)avio_alloc_context(tempbuf, m_bufSize, 0, (void*)this, _MpegReadbuffer, NULL, _MpegSeekbuffer);
pFormatCtx->pb = (AVIOContext*)m_pIOContext;
m_pIOContext = avio_alloc_context(tempbuf, m_bufSize, 0, (void*)this, _MpegReadbuffer, NULL, _MpegSeekbuffer);
pFormatCtx->pb = m_pIOContext;

// Open video file
if(avformat_open_input((AVFormatContext**)&m_pFormatCtx, NULL, NULL, NULL) != 0)
Expand Down Expand Up @@ -541,6 +541,12 @@ static int getNextHeaderPosition(u8* audioStream, int curpos, int limit, int fra
return -1;
}

int MediaEngine::getBufferedSize() {
// m_decodePos is technically "decoderNextReadPos", we want what has actually been decoded.
int buffer_left = m_pIOContext->buffer_size - (m_pIOContext->buf_ptr - m_pIOContext->buffer);
return m_readSize - m_decodePos + buffer_left;
}

int MediaEngine::getAudioSamples(u8* buffer) {
if (!m_demux) {
return 0;
Expand Down
5 changes: 3 additions & 2 deletions Core/HW/MediaEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

struct SwsContext;
struct AVFrame;
struct AVIOContext;

class MediaEngine
{
Expand All @@ -45,7 +46,7 @@ class MediaEngine
// Returns number of packets actually added.
int addStreamData(u8* buffer, int addSize);
int getRemainSize() { return m_streamSize - m_readSize;}
int getBufferedSize() { return m_readSize - m_decodePos; }
int getBufferedSize();

bool stepVideo(int videoPixelMode);
bool writeVideoImage(u8* buffer, int frameWidth = 512, int videoPixelMode = 3);
Expand Down Expand Up @@ -76,7 +77,7 @@ class MediaEngine
void *m_pCodecCtx;
AVFrame *m_pFrame;
AVFrame *m_pFrameRGB;
void *m_pIOContext;
AVIOContext *m_pIOContext;
int m_videoStream;
SwsContext *m_sws_ctx;
int m_sws_fmt;
Expand Down

0 comments on commit 17907b2

Please sign in to comment.