Return a more accurate mpeg ringbuffer decode pos.

This commit is contained in:
Unknown W. Brackets 2013-06-06 23:18:12 -07:00
parent 94cce219a8
commit 17907b204b
2 changed files with 13 additions and 6 deletions

View file

@ -109,8 +109,8 @@ void MediaEngine::closeMedia() {
av_free(m_pFrameRGB); av_free(m_pFrameRGB);
if (m_pFrame) if (m_pFrame)
av_free(m_pFrame); av_free(m_pFrame);
if (m_pIOContext && ((AVIOContext*)m_pIOContext)->buffer) if (m_pIOContext && m_pIOContext->buffer)
av_free(((AVIOContext*)m_pIOContext)->buffer); av_free(m_pIOContext->buffer);
if (m_pIOContext) if (m_pIOContext)
av_free(m_pIOContext); av_free(m_pIOContext);
if (m_pCodecCtx) if (m_pCodecCtx)
@ -183,8 +183,8 @@ bool MediaEngine::openContext() {
AVFormatContext *pFormatCtx = avformat_alloc_context(); AVFormatContext *pFormatCtx = avformat_alloc_context();
m_pFormatCtx = (void*)pFormatCtx; m_pFormatCtx = (void*)pFormatCtx;
m_pIOContext = (void*)avio_alloc_context(tempbuf, m_bufSize, 0, (void*)this, _MpegReadbuffer, NULL, _MpegSeekbuffer); m_pIOContext = avio_alloc_context(tempbuf, m_bufSize, 0, (void*)this, _MpegReadbuffer, NULL, _MpegSeekbuffer);
pFormatCtx->pb = (AVIOContext*)m_pIOContext; pFormatCtx->pb = m_pIOContext;
// Open video file // Open video file
if(avformat_open_input((AVFormatContext**)&m_pFormatCtx, NULL, NULL, NULL) != 0) if(avformat_open_input((AVFormatContext**)&m_pFormatCtx, NULL, NULL, NULL) != 0)
@ -541,6 +541,12 @@ static int getNextHeaderPosition(u8* audioStream, int curpos, int limit, int fra
return -1; 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) { int MediaEngine::getAudioSamples(u8* buffer) {
if (!m_demux) { if (!m_demux) {
return 0; return 0;

View file

@ -32,6 +32,7 @@
struct SwsContext; struct SwsContext;
struct AVFrame; struct AVFrame;
struct AVIOContext;
class MediaEngine class MediaEngine
{ {
@ -45,7 +46,7 @@ public:
// Returns number of packets actually added. // Returns number of packets actually added.
int addStreamData(u8* buffer, int addSize); int addStreamData(u8* buffer, int addSize);
int getRemainSize() { return m_streamSize - m_readSize;} int getRemainSize() { return m_streamSize - m_readSize;}
int getBufferedSize() { return m_readSize - m_decodePos; } int getBufferedSize();
bool stepVideo(int videoPixelMode); bool stepVideo(int videoPixelMode);
bool writeVideoImage(u8* buffer, int frameWidth = 512, int videoPixelMode = 3); bool writeVideoImage(u8* buffer, int frameWidth = 512, int videoPixelMode = 3);
@ -76,7 +77,7 @@ public:
void *m_pCodecCtx; void *m_pCodecCtx;
AVFrame *m_pFrame; AVFrame *m_pFrame;
AVFrame *m_pFrameRGB; AVFrame *m_pFrameRGB;
void *m_pIOContext; AVIOContext *m_pIOContext;
int m_videoStream; int m_videoStream;
SwsContext *m_sws_ctx; SwsContext *m_sws_ctx;
int m_sws_fmt; int m_sws_fmt;