Merge pull request #2217 from oioitff/mpeg-fix

Add support for multiple video/audio stream.
This commit is contained in:
Henrik Rydgård 2013-06-11 07:42:19 -07:00
commit 6b84743082
6 changed files with 33 additions and 20 deletions

View File

@ -515,15 +515,17 @@ int sceMpegRegistStream(u32 mpeg, u32 streamType, u32 streamNum)
return -1;
}
DEBUG_LOG(HLE, "sceMpegRegistStream(%08x, %i, %i)", mpeg, streamType, streamNum);
INFO_LOG(HLE, "sceMpegRegistStream(%08x, %i, %i)", mpeg, streamType, streamNum);
switch (streamType) {
case MPEG_AVC_STREAM:
ctx->avcRegistered = true;
ctx->mediaengine->setVideoStream(streamNum);
break;
case MPEG_AUDIO_STREAM:
case MPEG_ATRAC_STREAM:
ctx->atracRegistered = true;
ctx->mediaengine->setAudioStream(streamNum);
break;
case MPEG_PCM_STREAM:
ctx->pcmRegistered = true;

View File

@ -821,6 +821,8 @@ int scePsmfPlayerStart(u32 psmfPlayer, u32 psmfPlayerData, int initPts)
psmfplayer->psmfPlayerAvcAu.pts = initPts;
psmfplayer->status = PSMF_PLAYER_STATUS_PLAYING;
psmfplayer->mediaengine->openContext();
return 0;
}
@ -1076,6 +1078,7 @@ u32 scePsmfPlayerSelectSpecificVideo(u32 psmfPlayer, int videoCodec, int videoSt
psmfplayer->videoCodec = videoCodec;
psmfplayer->videoStreamNum = videoStreamNum;
psmfplayer->mediaengine->setVideoStream(videoStreamNum);
return 0;
}
@ -1090,6 +1093,7 @@ u32 scePsmfPlayerSelectSpecificAudio(u32 psmfPlayer, int audioCodec, int audioSt
psmfplayer->audioCodec = audioCodec;
psmfplayer->audioStreamNum = audioStreamNum;
psmfplayer->mediaengine->setAudioStream(audioStreamNum);
return 0;
}

View File

@ -88,6 +88,7 @@ MediaEngine::MediaEngine(): m_streamSize(0), m_readSize(0), m_decodedPos(0), m_p
m_pFrameRGB = 0;
m_pIOContext = 0;
m_videoStream = -1;
m_audioStream = -1;
m_buffer = 0;
m_demux = 0;
m_audioContext = 0;
@ -126,7 +127,6 @@ void MediaEngine::closeMedia() {
m_pIOContext = 0;
m_pCodecCtx = 0;
m_pFormatCtx = 0;
m_videoStream = -1;
m_pdata = 0;
m_demux = 0;
Atrac3plus_Decoder::CloseContext(&m_audioContext);
@ -177,6 +177,8 @@ bool MediaEngine::openContext() {
av_log_set_level(AV_LOG_VERBOSE);
av_log_set_callback(&ffmpeg_logger);
#endif
if (m_readSize <= 0x2000 || m_pFormatCtx || !m_pdata)
return false;
u8* tempbuf = (u8*)av_malloc(m_bufSize);
@ -191,15 +193,17 @@ bool MediaEngine::openContext() {
if(avformat_find_stream_info(m_pFormatCtx, NULL) < 0)
return false;
// Find the first video stream
for(int i = 0; i < (int)m_pFormatCtx->nb_streams; i++) {
if(m_pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
m_videoStream = i;
break;
if (m_videoStream == -1) {
// Find the first video stream
for(int i = 0; i < (int)m_pFormatCtx->nb_streams; i++) {
if(m_pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
m_videoStream = i;
break;
}
}
if(m_videoStream == -1)
return false;
}
if(m_videoStream == -1)
return false;
// Get a pointer to the codec context for the video stream
m_pCodecCtx = m_pFormatCtx->streams[m_videoStream]->codec;
@ -218,7 +222,7 @@ bool MediaEngine::openContext() {
int mpegoffset = bswap32(*(int*)(m_pdata + 8));
m_demux = new MpegDemux(m_pdata, m_streamSize, mpegoffset);
m_demux->setReadSize(m_readSize);
m_demux->demux();
m_demux->demux(m_audioStream);
m_audioPos = 0;
m_audioContext = Atrac3plus_Decoder::OpenContext();
m_isVideoEnd = false;
@ -245,8 +249,6 @@ bool MediaEngine::loadStream(u8* buffer, int readSize, int StreamSize)
return false;
memcpy(m_pdata, buffer, m_readSize);
if (readSize > 0x2000)
openContext();
return true;
}
@ -272,9 +274,6 @@ bool MediaEngine::loadFile(const char* filename)
m_readSize = infosize;
m_streamSize = infosize;
m_pdata = buf;
if (m_readSize > 0x2000)
openContext();
return true;
}
@ -288,7 +287,7 @@ int MediaEngine::addStreamData(u8* buffer, int addSize) {
openContext();
if (m_demux) {
m_demux->setReadSize(m_readSize);
m_demux->demux();
m_demux->demux(m_audioStream);
}
}
return size;

View File

@ -50,8 +50,14 @@ public:
void closeMedia();
bool loadStream(u8* buffer, int readSize, int StreamSize);
bool loadFile(const char* filename);
// open the mpeg context
bool openContext();
// Returns number of packets actually added.
int addStreamData(u8* buffer, int addSize);
void setVideoStream(int streamNum) { m_videoStream = streamNum; }
void setAudioStream(int streamNum) { m_audioStream = streamNum; }
int getRemainSize() { return m_streamSize - m_readSize;}
int getBufferedSize();
@ -76,7 +82,6 @@ public:
}
private:
bool openContext();
void updateSwsFormat(int videoPixelMode);
public:
@ -86,10 +91,11 @@ public:
AVFrame *m_pFrame;
AVFrame *m_pFrameRGB;
AVIOContext *m_pIOContext;
int m_videoStream;
SwsContext *m_sws_ctx;
int m_sws_fmt;
u8 *m_buffer;
int m_videoStream;
int m_audioStream;
int m_desWidth;
int m_desHeight;

View File

@ -140,10 +140,12 @@ int MpegDemux::demuxStream(bool bdemux, int startCode, int channel)
return channel;
}
void MpegDemux::demux()
void MpegDemux::demux(int audioChannel)
{
if (!m_audioStream)
m_audioStream = new u8[m_len - m_index];
if (audioChannel >= 0)
m_audioChannel = audioChannel;
while (m_index < m_len)
{
if (m_readSize != m_len && m_index + 2048 > m_readSize)

View File

@ -13,7 +13,7 @@ public:
void setReadSize(int readSize);
void demux();
void demux(int audioChannel);
// return its size
int getaudioStream(u8 **audioStream);