Skip to content

Commit

Permalink
Merge pull request #4993 from unknownbrackets/mpeg-minor
Browse files Browse the repository at this point in the history
Set the audio/video streams per sceMpegGet*Au()
  • Loading branch information
hrydgard committed Jan 3, 2014
2 parents af8a9bc + 4e92976 commit 4d4fb98
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
8 changes: 7 additions & 1 deletion Core/HLE/sceMpeg.cpp
Expand Up @@ -1019,6 +1019,8 @@ int sceMpegGetAvcAu(u32 mpeg, u32 streamId, u32 auAddr, u32 attrAddr)
return -1;
}

ctx->mediaengine->setVideoStream(streamInfo->second.num);

if (streamInfo->second.needsReset)
{
sceAu.pts = 0;
Expand Down Expand Up @@ -1099,6 +1101,10 @@ int sceMpegGetAtracAu(u32 mpeg, u32 streamId, u32 auAddr, u32 attrAddr)
sceAu.pts = 0;
streamInfo->second.needsReset = false;
}
if (streamInfo != ctx->streamMap.end())
ctx->mediaengine->setAudioStream(streamInfo->second.num);
else
WARN_LOG_REPORT(ME, "sceMpegGetAtracAu: invalid audio stream %08x", streamId);

// The audio can end earlier than the video does.
if (mpegRingbuffer.packetsFree == mpegRingbuffer.packets) {
Expand Down Expand Up @@ -1245,7 +1251,7 @@ u32 sceMpegAvcCopyYCbCr(u32 mpeg, u32 sourceAddr, u32 YCbCrAddr)

u32 sceMpegAtracDecode(u32 mpeg, u32 auAddr, u32 bufferAddr, int init)
{
DEBUG_LOG(ME, "UNIMPL sceMpegAtracDecode(%08x, %08x, %08x, %i)", mpeg, auAddr, bufferAddr, init);
DEBUG_LOG(ME, "sceMpegAtracDecode(%08x, %08x, %08x, %i)", mpeg, auAddr, bufferAddr, init);

MpegContext *ctx = getMpegCtx(mpeg);
if (!ctx) {
Expand Down
50 changes: 38 additions & 12 deletions Core/HW/MediaEngine.cpp
Expand Up @@ -266,19 +266,9 @@ bool MediaEngine::openContext() {
return false;
}

// Get a pointer to the codec context for the video stream
m_pCodecCtx = m_pFormatCtx->streams[m_videoStream]->codec;

// Find the decoder for the video stream
AVCodec *pCodec = avcodec_find_decoder(m_pCodecCtx->codec_id);
if(pCodec == NULL)
if (!setVideoStream(m_videoStream, true))
return false;

// Open codec
AVDictionary *optionsDict = 0;
if(avcodec_open2(m_pCodecCtx, pCodec, &optionsDict)<0)
return false; // Could not open codec

setVideoDim();
m_audioContext = AT3Create();
m_isVideoEnd = false;
Expand Down Expand Up @@ -341,7 +331,6 @@ int MediaEngine::addStreamData(u8* buffer, int addSize) {
size = 0;
if (m_demux) {
m_demux->addStreamData(buffer, addSize);
m_demux->demux(m_audioStream);
}
#ifdef USE_FFMPEG
if (!m_pFormatCtx && m_pdata->getQueueSize() >= 2048) {
Expand All @@ -358,6 +347,39 @@ int MediaEngine::addStreamData(u8* buffer, int addSize) {
return size;
}

bool MediaEngine::setVideoStream(int streamNum, bool force) {
if (m_videoStream == streamNum && !force) {
// Yay, nothing to do.
return true;
}

m_videoStream = streamNum;
#ifdef USE_FFMPEG
if (m_pFormatCtx) {
if (m_pCodecCtx) {
avcodec_close(m_pCodecCtx);
}

// Get a pointer to the codec context for the video stream
m_pCodecCtx = m_pFormatCtx->streams[m_videoStream]->codec;

// Find the decoder for the video stream
AVCodec *pCodec = avcodec_find_decoder(m_pCodecCtx->codec_id);
if (pCodec == NULL) {
return false;
}

// Open codec
AVDictionary *optionsDict = 0;
if (avcodec_open2(m_pCodecCtx, pCodec, &optionsDict) < 0) {
return false; // Could not open codec
}
}
#endif

return true;
}

bool MediaEngine::setVideoDim(int width, int height)
{
#ifdef USE_FFMPEG
Expand Down Expand Up @@ -670,6 +692,10 @@ int MediaEngine::getAudioSamples(u32 bufferPtr) {
if (!m_demux) {
return 0;
}

// Demux now (rather than on add data) so that we select the right stream.
m_demux->demux(m_audioStream);

u8 *audioFrame = 0;
int headerCode1, headerCode2;
int frameSize = m_demux->getNextaudioFrame(&audioFrame, &headerCode1, &headerCode2);
Expand Down
2 changes: 1 addition & 1 deletion Core/HW/MediaEngine.h
Expand Up @@ -65,7 +65,7 @@ class MediaEngine
// Returns number of packets actually added. I guess the buffer might be full.
int addStreamData(u8* buffer, int addSize);

void setVideoStream(int streamNum) { m_videoStream = streamNum; }
bool setVideoStream(int streamNum, bool force = false);
void setAudioStream(int streamNum) { m_audioStream = streamNum; }

u8 *getFrameImage();
Expand Down

3 comments on commit 4d4fb98

@solarmystic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit causes the FFIV crashing during FMV playback issue to occur again. See #4550 (comment) for further details.

@daniel229
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crashing Prince of Persia forgotten sands as well.

@unknownbrackets
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Darn, that's strange.

-[Unknown]

Please sign in to comment.