int sceAudiocodecDecode(u32 ctxPtr, int codec) { if (!ctxPtr){ ERROR_LOG_REPORT(ME, "sceAudiocodecDecode(%08x, %i (%s)) got NULL pointer", ctxPtr, codec, GetCodecName(codec)); return -1; } if (IsValidCodec(codec)){ // Use SimpleAudioDec to decode audio auto ctx = PSPPointer<AudioCodecContext>::Create(ctxPtr); // On stack, no need to allocate. int outbytes = 0; // find a decoder in audioList auto decoder = findDecoder(ctxPtr); if (!decoder && oldStateLoaded) { // We must have loaded an old state that did not have sceAudiocodec information. // Fake it by creating the desired context. decoder = new SimpleAudio(codec); decoder->SetCtxPtr(ctxPtr); audioList[ctxPtr] = decoder; } if (decoder != NULL) { // Decode audio decoder->Decode(Memory::GetPointer(ctx->inDataPtr), ctx->inDataSize, Memory::GetPointer(ctx->outDataPtr), &outbytes); } DEBUG_LOG(ME, "sceAudiocodecDec(%08x, %i (%s))", ctxPtr, codec, GetCodecName(codec)); return 0; } ERROR_LOG_REPORT(ME, "UNIMPL sceAudiocodecDecode(%08x, %i (%s))", ctxPtr, codec, GetCodecName(codec)); return 0; }
int MediaEngine::getAudioSamples(u32 bufferPtr) { if (!Memory::IsValidAddress(bufferPtr)) { ERROR_LOG_REPORT(ME, "Ignoring bad audio decode address %08x during video playback", bufferPtr); } u8 *buffer = Memory::GetPointer(bufferPtr); if (!m_demux) { return 0; } u8 *audioFrame = 0; int headerCode1, headerCode2; int frameSize = getNextAudioFrame(&audioFrame, &headerCode1, &headerCode2); if (frameSize == 0) { return 0; } int outbytes = 0; if (m_audioContext != nullptr) { if (headerCode1 == 0x24) { // This means mono audio - tell the decoder to expect it before the first frame. // Note that it will always send us back stereo audio. m_audioContext->SetChannels(1); } if (!m_audioContext->Decode(audioFrame, frameSize, buffer, &outbytes)) { ERROR_LOG(ME, "Audio (%s) decode failed during video playback", GetCodecName(m_audioType)); } #ifndef MOBILE_DEVICE CBreakPoints::ExecMemCheck(bufferPtr, true, outbytes, currentMIPS->pc); #endif } return 0x2000; }
int sceAudiocodecInit(u32 ctxPtr, int codec) { if (isValidCodec(codec)) { // Create audio decoder for given audio codec and push it into AudioList if (removeDecoder(ctxPtr)) { WARN_LOG_REPORT(HLE, "sceAudiocodecInit(%08x, %d): replacing existing context", ctxPtr, codec); } auto decoder = new SimpleAudio(ctxPtr, codec); audioList[ctxPtr] = decoder; INFO_LOG(ME, "sceAudiocodecInit(%08x, %i (%s))", ctxPtr, codec, GetCodecName(codec)); DEBUG_LOG(ME, "Number of playing sceAudioCodec audios : %d", (int)audioList.size()); return 0; } ERROR_LOG_REPORT(ME, "sceAudiocodecInit(%08x, %i (%s)): Unknown audio codec %i", ctxPtr, codec, GetCodecName(codec), codec); return 0; }
int MediaEngine::getAudioSamples(u32 bufferPtr) { if (!Memory::IsValidAddress(bufferPtr)) { ERROR_LOG_REPORT(ME, "Ignoring bad audio decode address %08x during video playback", bufferPtr); } u8 *buffer = Memory::GetPointer(bufferPtr); if (!m_demux) { return 0; } // When m_demux , increment pts m_audiopts += 4180; // 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); if (frameSize == 0) { m_noAudioData = true; return 0; } int outbytes = 0; if (m_audioContext != NULL) { if (!AudioDecode(m_audioContext, audioFrame, frameSize, &outbytes, buffer)) { ERROR_LOG(ME, "Audio (%s) decode failed during video playback", GetCodecName(m_audioType)); } } if (headerCode1 == 0x24) { // it a mono atrac3plus, convert it to stereo s16 *outbuf = (s16*)buffer; s16 *inbuf = (s16*)buffer; for (int i = 0x800 - 1; i >= 0; i--) { s16 sample = inbuf[i]; outbuf[i * 2] = sample; outbuf[i * 2 + 1] = sample; } } m_noAudioData = false; return 0x2000; }
int MediaEngine::getAudioSamples(u32 bufferPtr) { if (!Memory::IsValidAddress(bufferPtr)) { ERROR_LOG_REPORT(ME, "Ignoring bad audio decode address %08x during video playback", bufferPtr); } u8 *buffer = Memory::GetPointer(bufferPtr); if (!m_demux) { return 0; } u8 *audioFrame = 0; int headerCode1, headerCode2; int frameSize = getNextAudioFrame(&audioFrame, &headerCode1, &headerCode2); if (frameSize == 0) { return 0; } int outbytes = 0; if (m_audioContext != NULL) { if (!m_audioContext->Decode(audioFrame, frameSize, buffer, &outbytes)) { ERROR_LOG(ME, "Audio (%s) decode failed during video playback", GetCodecName(m_audioType)); } #ifndef MOBILE_DEVICE CBreakPoints::ExecMemCheck(bufferPtr, true, outbytes, currentMIPS->pc); #endif } if (headerCode1 == 0x24) { // it a mono atrac3plus, convert it to stereo s16 *outbuf = (s16*)buffer; s16 *inbuf = (s16*)buffer; for (int i = 0x800 - 1; i >= 0; i--) { s16 sample = inbuf[i]; outbuf[i * 2] = sample; outbuf[i * 2 + 1] = sample; } } return 0x2000; }
int svlFilterVideoFileWriter::GetCodecName(std::string &encoder, unsigned int videoch) const { encoder = GetCodecName(videoch); if (encoder.empty()) return SVL_FAIL; return SVL_OK; }
QString Format::GetCodecID () const { return GetCodecName (); }
void SimpleAudio::Init() { #ifdef USE_FFMPEG avcodec_register_all(); av_register_all(); InitFFmpeg(); frame_ = av_frame_alloc(); // Get Audio Codec ctx int audioCodecId = GetAudioCodecID(audioType); if (!audioCodecId) { ERROR_LOG(ME, "This version of FFMPEG does not support Audio codec type: %08x. Update your submodule.", audioType); return; } // Find decoder codec_ = avcodec_find_decoder((AVCodecID)audioCodecId); if (!codec_) { // Eh, we shouldn't even have managed to compile. But meh. ERROR_LOG(ME, "This version of FFMPEG does not support AV_CODEC_ctx for audio (%s). Update your submodule.", GetCodecName(audioType)); return; } // Allocate codec context codecCtx_ = avcodec_alloc_context3(codec_); if (!codecCtx_) { ERROR_LOG(ME, "Failed to allocate a codec context"); return; } codecCtx_->channels = channels_; codecCtx_->channel_layout = channels_ == 2 ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; codecCtx_->sample_rate = sample_rate_; codecOpen_ = false; #endif // USE_FFMPEG }
int sceAudiocodecGetEDRAM(u32 ctxPtr, int codec) { WARN_LOG(ME, "UNIMPL sceAudiocodecGetEDRAM(%08x, %i (%s))", ctxPtr, codec, GetCodecName(codec)); return 0; }
int sceAudiocodecCheckNeedMem(u32 ctxPtr, int codec) { WARN_LOG(ME, "UNIMPL sceAudiocodecCheckNeedMem(%08x, %i (%s))", ctxPtr, codec, GetCodecName(codec)); return 0; }
int sceAudiocodecGetInfo(u32 ctxPtr, int codec) { ERROR_LOG_REPORT(ME, "UNIMPL sceAudiocodecGetInfo(%08x, %i (%s))", ctxPtr, codec, GetCodecName(codec)); return 0; }
bool SimpleAudio::ResetCodecCtx(int channels, int samplerate) { #ifdef USE_FFMPEG if (codecCtx_) avcodec_close(codecCtx_); // Find decoder int audioCodecId = GetAudioCodecID(audioType); codec_ = avcodec_find_decoder((AVCodecID)audioCodecId); if (!codec_) { // Eh, we shouldn't even have managed to compile. But meh. ERROR_LOG(ME, "This version of FFMPEG does not support AV_CODEC_ctx for audio (%s). Update your submodule.", GetCodecName(audioType)); return false; } codecCtx_->channels = channels; codecCtx_->channel_layout = channels==2?AV_CH_LAYOUT_STEREO:AV_CH_LAYOUT_MONO; codecCtx_->sample_rate = samplerate; codecOpen_ = false; return true; #endif return false; }
SimpleAudio::SimpleAudio(int audioType) : codec_(0), codecCtx_(0), swrCtx_(0), audioType(audioType), outSamples(0), wanted_resample_freq(44100){ #ifdef USE_FFMPEG avcodec_register_all(); av_register_all(); InitFFmpeg(); frame_ = av_frame_alloc(); // Get Audio Codec ID if (!GetAudioCodecID(audioType)){ ERROR_LOG(ME, "This version of FFMPEG does not support Audio codec type: %08x. Update your submodule.", audioType); return; } // Find decoder codec_ = avcodec_find_decoder(audioCodecId); if (!codec_) { // Eh, we shouldn't even have managed to compile. But meh. ERROR_LOG(ME, "This version of FFMPEG does not support AV_CODEC_ID for audio (%s). Update your submodule.", GetCodecName(audioType)); return; } // Allocate codec context codecCtx_ = avcodec_alloc_context3(codec_); if (!codecCtx_) { ERROR_LOG(ME, "Failed to allocate a codec context"); return; } codecCtx_->channels = 2; codecCtx_->channel_layout = AV_CH_LAYOUT_STEREO; codecCtx_->sample_rate = 44100; // Open codec AVDictionary *opts = 0; if (avcodec_open2(codecCtx_, codec_, &opts) < 0) { ERROR_LOG(ME, "Failed to open codec"); return; } av_dict_free(&opts); #endif // USE_FFMPEG }
bool SimpleAudio::ResetCodecCtx(int channels, int samplerate){ #ifdef USE_FFMPEG if (codecCtx_) avcodec_close(codecCtx_); // Find decoder codec_ = avcodec_find_decoder(audioCodecId); if (!codec_) { // Eh, we shouldn't even have managed to compile. But meh. ERROR_LOG(ME, "This version of FFMPEG does not support AV_CODEC_ctx for audio (%s). Update your submodule.", GetCodecName(audioType)); return false; } codecCtx_->channels = channels; codecCtx_->channel_layout = channels==2?AV_CH_LAYOUT_STEREO:AV_CH_LAYOUT_MONO; codecCtx_->sample_rate = samplerate; // Open codec AVDictionary *opts = 0; if (avcodec_open2(codecCtx_, codec_, &opts) < 0) { ERROR_LOG(ME, "Failed to open codec"); av_dict_free(&opts); return false; } av_dict_free(&opts); return true; #endif return false; }