diff options
10 files changed, 72 insertions, 75 deletions
diff --git a/tools/depends/native/TexturePacker/src/decoder/GIFDecoder.cpp b/tools/depends/native/TexturePacker/src/decoder/GIFDecoder.cpp index 7e5179b0cc..d7c5e2ac55 100644 --- a/tools/depends/native/TexturePacker/src/decoder/GIFDecoder.cpp +++ b/tools/depends/native/TexturePacker/src/decoder/GIFDecoder.cpp @@ -31,6 +31,8 @@ bool GIFDecoder::CanDecode(const std::string &filename) bool GIFDecoder::LoadFile(const std::string &filename, DecodedFrames &frames) { int n = 0; + bool result = false; + GifHelper *gifImage = new GifHelper(); if (gifImage->LoadGif(filename.c_str())) { @@ -53,28 +55,20 @@ bool GIFDecoder::LoadFile(const std::string &filename, DecodedFrames &frames) frame.rgbaImage.bbp = 32; frame.rgbaImage.pitch = pitch; frame.delay = extractedFrames[i]->m_delay; + frame.decoder = this; frames.frameList.push_back(frame); } } - frames.user = gifImage; - return true; - } - else - { - delete gifImage; - return false; + result = true; } + delete gifImage; + return result; } -void GIFDecoder::FreeDecodedFrames(DecodedFrames &frames) +void GIFDecoder::FreeDecodedFrame(DecodedFrame &frame) { - for (unsigned int i = 0; i < frames.frameList.size(); i++) - { - delete [] frames.frameList[i].rgbaImage.pixels; - } - delete (GifHelper *)frames.user; - frames.clear(); + delete [] frame.rgbaImage.pixels; } void GIFDecoder::FillSupportedExtensions() diff --git a/tools/depends/native/TexturePacker/src/decoder/GIFDecoder.h b/tools/depends/native/TexturePacker/src/decoder/GIFDecoder.h index 6e9ea6c4be..8f0b42d822 100644 --- a/tools/depends/native/TexturePacker/src/decoder/GIFDecoder.h +++ b/tools/depends/native/TexturePacker/src/decoder/GIFDecoder.h @@ -28,7 +28,7 @@ class GIFDecoder : public IDecoder ~GIFDecoder() override = default; bool CanDecode(const std::string &filename) override; bool LoadFile(const std::string &filename, DecodedFrames &frames) override; - void FreeDecodedFrames(DecodedFrames &frames) override; + void FreeDecodedFrame(DecodedFrame &frame) override; const char* GetImageFormatName() override { return "GIF"; } const char* GetDecoderName() override { return "libgif"; } protected: diff --git a/tools/depends/native/TexturePacker/src/decoder/IDecoder.h b/tools/depends/native/TexturePacker/src/decoder/IDecoder.h index b197296d9b..28243acbf1 100644 --- a/tools/depends/native/TexturePacker/src/decoder/IDecoder.h +++ b/tools/depends/native/TexturePacker/src/decoder/IDecoder.h @@ -23,6 +23,34 @@ #include <string> #include <vector> +/* forward declarations */ + +class DecodedFrame; +class DecodedFrames; + +class IDecoder +{ + public: + virtual ~IDecoder() = default; + virtual bool CanDecode(const std::string &filename) = 0; + virtual bool LoadFile(const std::string &filename, DecodedFrames &frames) = 0; + virtual void FreeDecodedFrame(DecodedFrame &frame) = 0; + virtual const char* GetImageFormatName() = 0; + virtual const char* GetDecoderName() = 0; + + const std::vector<std::string>& GetSupportedExtensions() + { + m_supportedExtensions.clear(); + FillSupportedExtensions(); + return m_supportedExtensions; + } + + protected: + virtual void FillSupportedExtensions() = 0; + //fill this with extensions in FillSupportedExtensions like ".png" + std::vector<std::string> m_supportedExtensions; +}; + class RGBAImage { public: @@ -39,43 +67,32 @@ class DecodedFrame { public: DecodedFrame() : delay(0) { } - RGBAImage rgbaImage; /* rgbaimage for this frame */ - int delay; /* Frame delay in ms */ + RGBAImage rgbaImage; /* rgbaimage for this frame */ + int delay = 0; /* Frame delay in ms */ + IDecoder* decoder = nullptr; /* Pointer to decoder */ }; class DecodedFrames { public: - DecodedFrames(): user(NULL) {} + DecodedFrames() = default; std::vector<DecodedFrame> frameList; - void *user; /* used internally*/ void clear() { + for (auto f : frameList) + { + if (f.decoder != NULL) + { + f.decoder->FreeDecodedFrame(f); + } + else + { + fprintf(stderr, + "ERROR: %s - can not determine decoder type for frame!\n", + __FUNCTION__); + } + } frameList.clear(); - user = NULL; } }; - -class IDecoder -{ - public: - virtual ~IDecoder() = default; - virtual bool CanDecode(const std::string &filename) = 0; - virtual bool LoadFile(const std::string &filename, DecodedFrames &frames) = 0; - virtual void FreeDecodedFrames(DecodedFrames &frames) = 0; - virtual const char* GetImageFormatName() = 0; - virtual const char* GetDecoderName() = 0; - - const std::vector<std::string>& GetSupportedExtensions() - { - m_supportedExtensions.clear(); - FillSupportedExtensions(); - return m_supportedExtensions; - } - - protected: - virtual void FillSupportedExtensions() = 0; - //fill this with extensions in FillSupportedExtensions like ".png" - std::vector<std::string> m_supportedExtensions; -}; diff --git a/tools/depends/native/TexturePacker/src/decoder/JPGDecoder.cpp b/tools/depends/native/TexturePacker/src/decoder/JPGDecoder.cpp index 4022dc719f..15a646f95b 100644 --- a/tools/depends/native/TexturePacker/src/decoder/JPGDecoder.cpp +++ b/tools/depends/native/TexturePacker/src/decoder/JPGDecoder.cpp @@ -84,7 +84,6 @@ bool JPGDecoder::LoadFile(const std::string &filename, DecodedFrames &frames) // Image Size is calculated as (width * height * bytes per pixel = 4 ImageSize = cinfo.image_width * cinfo.image_height * 4; - frames.user = NULL; DecodedFrame frame; frame.rgbaImage.pixels = (char *)new char[ImageSize]; @@ -115,20 +114,18 @@ bool JPGDecoder::LoadFile(const std::string &filename, DecodedFrames &frames) frame.rgbaImage.width = cinfo.image_width; frame.rgbaImage.bbp = 32; frame.rgbaImage.pitch = 4 * cinfo.image_width; + + frame.decoder = this; + frames.frameList.push_back(frame); delete arq; return true; } -void JPGDecoder::FreeDecodedFrames(DecodedFrames &frames) +void JPGDecoder::FreeDecodedFrame(DecodedFrame &frame) { - for (unsigned int i = 0; i < frames.frameList.size(); i++) - { - delete [] frames.frameList[i].rgbaImage.pixels; - } - - frames.clear(); + delete [] frame.rgbaImage.pixels; } void JPGDecoder::FillSupportedExtensions() diff --git a/tools/depends/native/TexturePacker/src/decoder/JPGDecoder.h b/tools/depends/native/TexturePacker/src/decoder/JPGDecoder.h index 30430e79f9..bbf23ba7b3 100644 --- a/tools/depends/native/TexturePacker/src/decoder/JPGDecoder.h +++ b/tools/depends/native/TexturePacker/src/decoder/JPGDecoder.h @@ -28,7 +28,7 @@ class JPGDecoder : public IDecoder ~JPGDecoder() override = default; bool CanDecode(const std::string &filename) override; bool LoadFile(const std::string &filename, DecodedFrames &frames) override; - void FreeDecodedFrames(DecodedFrames &frames) override; + void FreeDecodedFrame(DecodedFrame &frame) override; const char* GetImageFormatName() override { return "JPG"; } const char* GetDecoderName() override { return "libjpeg"; } protected: diff --git a/tools/depends/native/TexturePacker/src/decoder/PNGDecoder.cpp b/tools/depends/native/TexturePacker/src/decoder/PNGDecoder.cpp index 96ca0b461f..e5ca91b5c6 100644 --- a/tools/depends/native/TexturePacker/src/decoder/PNGDecoder.cpp +++ b/tools/depends/native/TexturePacker/src/decoder/PNGDecoder.cpp @@ -214,7 +214,6 @@ bool PNGDecoder::LoadFile(const std::string &filename, DecodedFrames &frames) // read the png into image_data through row_pointers png_read_image(png_ptr, row_pointers); - frames.user = NULL; DecodedFrame frame; frame.rgbaImage.pixels = (char *)image_data; @@ -222,6 +221,9 @@ bool PNGDecoder::LoadFile(const std::string &filename, DecodedFrames &frames) frame.rgbaImage.width = temp_width; frame.rgbaImage.bbp = 32; frame.rgbaImage.pitch = 4 * temp_width; + + frame.decoder = this; + frames.frameList.push_back(frame); // clean up png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); @@ -229,14 +231,9 @@ bool PNGDecoder::LoadFile(const std::string &filename, DecodedFrames &frames) return true; } -void PNGDecoder::FreeDecodedFrames(DecodedFrames &frames) +void PNGDecoder::FreeDecodedFrame(DecodedFrame &frame) { - for (unsigned int i = 0; i < frames.frameList.size(); i++) - { - delete [] frames.frameList[i].rgbaImage.pixels; - } - - frames.clear(); + delete [] frame.rgbaImage.pixels; } void PNGDecoder::FillSupportedExtensions() diff --git a/tools/depends/native/TexturePacker/src/decoder/PNGDecoder.h b/tools/depends/native/TexturePacker/src/decoder/PNGDecoder.h index 3b62a23e93..c7dba764cb 100644 --- a/tools/depends/native/TexturePacker/src/decoder/PNGDecoder.h +++ b/tools/depends/native/TexturePacker/src/decoder/PNGDecoder.h @@ -28,7 +28,7 @@ class PNGDecoder : public IDecoder ~PNGDecoder() override = default; bool CanDecode(const std::string &filename) override; bool LoadFile(const std::string &filename, DecodedFrames &frames) override; - void FreeDecodedFrames(DecodedFrames &frames) override; + void FreeDecodedFrame(DecodedFrame &frame) override; const char* GetImageFormatName() override { return "PNG"; } const char* GetDecoderName() override { return "libpng"; } protected: diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.cpp index 6e37eb931c..11e65b6490 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.cpp +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.cpp @@ -311,7 +311,6 @@ CDVDVideoCodecAndroidMediaCodec::CDVDVideoCodecAndroidMediaCodec(CProcessInfo &p , m_formatname("mediacodec") , m_opened(false) , m_jnivideoview(nullptr) -, m_jnisurface(nullptr) , m_textureId(0) , m_OutputDuration(0) , m_fpsDuration(0) @@ -796,10 +795,6 @@ void CDVDVideoCodecAndroidMediaCodec::Dispose() } ReleaseSurfaceTexture(); - if (m_jnisurface) - m_jnisurface->release(); - m_jnisurface = nullptr; - m_InstanceGuard.exchange(false); if (m_render_surface) { @@ -1223,10 +1218,9 @@ bool CDVDVideoCodecAndroidMediaCodec::ConfigureMediaCodec(void) // configure and start the codec. // use the MediaFormat that we have setup. // use a null MediaCrypto, our content is not encrypted. - - int flags = 0; m_codec->configure(mediaformat, m_jnivideosurface, - m_crypto ? *m_crypto : CJNIMediaCrypto(jni::jhobject(NULL)), flags); + m_crypto ? *m_crypto : CJNIMediaCrypto(jni::jhobject(NULL)), 0); + if (xbmc_jnienv()->ExceptionCheck()) { xbmc_jnienv()->ExceptionClear(); @@ -1446,7 +1440,7 @@ void CDVDVideoCodecAndroidMediaCodec::InitSurfaceTexture(void) m_surfaceTexture = std::shared_ptr<CJNISurfaceTexture>(new CJNISurfaceTexture(m_textureId)); // hook the surfaceTexture OnFrameAvailable callback m_frameAvailable = std::shared_ptr<CDVDMediaCodecOnFrameAvailable>(new CDVDMediaCodecOnFrameAvailable(m_surfaceTexture)); - m_jnisurface = new CJNISurface(*m_surfaceTexture); + m_jnivideosurface = CJNISurface(*m_surfaceTexture); } else { @@ -1468,7 +1462,7 @@ void CDVDVideoCodecAndroidMediaCodec::ReleaseSurfaceTexture(void) // it is safe to delete here even though these items // were created in the main thread instance - SAFE_DELETE(m_jnisurface); + m_jnivideosurface = CJNISurface(jni::jhobject(NULL)); m_frameAvailable.reset(); m_surfaceTexture.reset(); @@ -1509,8 +1503,8 @@ void CDVDVideoCodecAndroidMediaCodec::surfaceDestroyed(CJNISurfaceHolder holder) if (m_state != MEDIACODEC_STATE_STOPPED && m_state != MEDIACODEC_STATE_UNINITIALIZED) { m_state = MEDIACODEC_STATE_STOPPED; - if (m_jnisurface) - m_jnisurface->release(); + if (m_jnivideosurface) + m_jnivideosurface.release(); m_codec->stop(); xbmc_jnienv()->ExceptionClear(); } diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.h b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.h index d07f7e1cff..da4ac8e931 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.h +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.h @@ -147,7 +147,6 @@ protected: int m_noPictureLoop; std::shared_ptr<CJNIXBMCVideoView> m_jnivideoview; - CJNISurface* m_jnisurface; CJNISurface m_jnivideosurface; unsigned int m_textureId; std::shared_ptr<CJNIMediaCodec> m_codec; diff --git a/xbmc/input/InputManager.cpp b/xbmc/input/InputManager.cpp index 012866c566..522fddd83c 100644 --- a/xbmc/input/InputManager.cpp +++ b/xbmc/input/InputManager.cpp @@ -234,7 +234,6 @@ bool CInputManager::ProcessEventServer(int windowId, float frameTime) if (wKeyID & ES_FLAG_UNICODE) { key = CKey(0u, 0u, static_cast<wchar_t>(wKeyID & ~ES_FLAG_UNICODE), 0, 0, 0, 0); - key.SetFromService(true); return OnKey(key); } |