diff options
author | davilla <davilla@4pi.com> | 2011-07-18 01:52:22 -0400 |
---|---|---|
committer | davilla <davilla@4pi.com> | 2011-07-18 01:52:50 -0400 |
commit | ce42254708ef6d17bf8e06cafe35f4f7c2fdea20 (patch) | |
tree | bc09f12900a9c04e584ce2d18b3e995ea32f54f1 | |
parent | 2f7f554b32e947e18e2182ab6787f6f8dd2aa421 (diff) |
add 3GPP/TX3G (aka MPEG-4 Timed Text) Subtitle support, millions of XBMC/Handbrake cry out in joy
-rw-r--r-- | XBMC-ATV2.xcodeproj/project.pbxproj | 6 | ||||
-rw-r--r-- | XBMC-IOS.xcodeproj/project.pbxproj | 6 | ||||
-rw-r--r-- | XBMC.xcodeproj/project.pbxproj | 8 | ||||
-rw-r--r-- | project/VS2010Express/XBMC.vcxproj | 4 | ||||
-rw-r--r-- | project/VS2010Express/XBMC.vcxproj.filters | 8 | ||||
-rw-r--r-- | xbmc/cores/dvdplayer/DVDCodecs/DVDFactoryCodec.cpp | 6 | ||||
-rw-r--r-- | xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecTX3G.cpp | 235 | ||||
-rw-r--r-- | xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecTX3G.h | 42 | ||||
-rw-r--r-- | xbmc/cores/dvdplayer/DVDCodecs/Overlay/Makefile.in | 1 |
9 files changed, 314 insertions, 2 deletions
diff --git a/XBMC-ATV2.xcodeproj/project.pbxproj b/XBMC-ATV2.xcodeproj/project.pbxproj index 84e0b004aa..f8ed3d1d64 100644 --- a/XBMC-ATV2.xcodeproj/project.pbxproj +++ b/XBMC-ATV2.xcodeproj/project.pbxproj @@ -919,6 +919,7 @@ F5AE41131341751E0004BD79 /* XBMCOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5AE41061341751E0004BD79 /* XBMCOperations.cpp */; }; F5AE453B134D2E720004BD79 /* JSONServiceDescription.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5AE4539134D2E720004BD79 /* JSONServiceDescription.cpp */; }; F5B13E0113344F310045076D /* DarwinUtils.mm in Sources */ = {isa = PBXBuildFile; fileRef = F5B13E0013344F310045076D /* DarwinUtils.mm */; }; + F5CEE72C13D3F9AC00225F72 /* DVDOverlayCodecTX3G.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5CEE72B13D3F9AC00225F72 /* DVDOverlayCodecTX3G.cpp */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -2868,6 +2869,8 @@ F5AE453A134D2E720004BD79 /* JSONServiceDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSONServiceDescription.h; sourceTree = "<group>"; }; F5B13DFF13344F2A0045076D /* DarwinUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DarwinUtils.h; sourceTree = "<group>"; }; F5B13E0013344F310045076D /* DarwinUtils.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DarwinUtils.mm; sourceTree = "<group>"; }; + F5CEE72B13D3F9AC00225F72 /* DVDOverlayCodecTX3G.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DVDOverlayCodecTX3G.cpp; sourceTree = "<group>"; }; + F5CEE72D13D3F9B300225F72 /* DVDOverlayCodecTX3G.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DVDOverlayCodecTX3G.h; sourceTree = "<group>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -3583,6 +3586,8 @@ F56C7276131EC151000AD0F6 /* DVDOverlayCodecFFmpeg.h */, F56C7277131EC151000AD0F6 /* DVDOverlayCodecText.cpp */, F56C7278131EC151000AD0F6 /* DVDOverlayCodecText.h */, + F5CEE72B13D3F9AC00225F72 /* DVDOverlayCodecTX3G.cpp */, + F5CEE72D13D3F9B300225F72 /* DVDOverlayCodecTX3G.h */, F56C7279131EC151000AD0F6 /* DVDOverlayImage.h */, F56C727A131EC151000AD0F6 /* DVDOverlaySpu.h */, F56C727B131EC151000AD0F6 /* DVDOverlayText.h */, @@ -6712,6 +6717,7 @@ 1830216013B8E35300770920 /* controledit.cpp in Sources */, DF27E25C13C23CCA002514FE /* InertialScrollingHandler.cpp in Sources */, 18ECC9AA13CF17EB00A9ED6C /* StreamUtils.cpp in Sources */, + F5CEE72C13D3F9AC00225F72 /* DVDOverlayCodecTX3G.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/XBMC-IOS.xcodeproj/project.pbxproj b/XBMC-IOS.xcodeproj/project.pbxproj index 70b93538a3..bf419f0b6a 100644 --- a/XBMC-IOS.xcodeproj/project.pbxproj +++ b/XBMC-IOS.xcodeproj/project.pbxproj @@ -919,6 +919,7 @@ F5AE4166134175520004BD79 /* XBMCOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5AE4159134175520004BD79 /* XBMCOperations.cpp */; }; F5AE4530134D2E3E0004BD79 /* JSONServiceDescription.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5AE452E134D2E3E0004BD79 /* JSONServiceDescription.cpp */; }; F5B13DCF1334490D0045076D /* DarwinUtils.mm in Sources */ = {isa = PBXBuildFile; fileRef = F5B13DCE1334490D0045076D /* DarwinUtils.mm */; }; + F5CEE73013D3F9D100225F72 /* DVDOverlayCodecTX3G.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5CEE72F13D3F9D100225F72 /* DVDOverlayCodecTX3G.cpp */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -2868,6 +2869,8 @@ F5AE539813673FC70004BD79 /* IOSAudioRingBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IOSAudioRingBuffer.h; path = AudioRenderers/IOSAudioRingBuffer.h; sourceTree = "<group>"; }; F5B13DCD1334490D0045076D /* DarwinUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DarwinUtils.h; sourceTree = "<group>"; }; F5B13DCE1334490D0045076D /* DarwinUtils.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DarwinUtils.mm; sourceTree = "<group>"; }; + F5CEE72F13D3F9D100225F72 /* DVDOverlayCodecTX3G.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DVDOverlayCodecTX3G.cpp; sourceTree = "<group>"; }; + F5CEE73113D3F9D800225F72 /* DVDOverlayCodecTX3G.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DVDOverlayCodecTX3G.h; sourceTree = "<group>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -3945,6 +3948,8 @@ F56C825A131F42E6000AD0F6 /* DVDOverlayCodecFFmpeg.h */, F56C825B131F42E6000AD0F6 /* DVDOverlayCodecText.cpp */, F56C825C131F42E6000AD0F6 /* DVDOverlayCodecText.h */, + F5CEE72F13D3F9D100225F72 /* DVDOverlayCodecTX3G.cpp */, + F5CEE73113D3F9D800225F72 /* DVDOverlayCodecTX3G.h */, F56C825D131F42E6000AD0F6 /* DVDOverlayImage.h */, F56C825E131F42E7000AD0F6 /* DVDOverlaySpu.h */, F56C825F131F42E7000AD0F6 /* DVDOverlayText.h */, @@ -6727,6 +6732,7 @@ 1830219E13B8E37300770920 /* controledit.cpp in Sources */, DF27E23613C23CAC002514FE /* InertialScrollingHandler.cpp in Sources */, 18ECC99D13CF17D200A9ED6C /* StreamUtils.cpp in Sources */, + F5CEE73013D3F9D100225F72 /* DVDOverlayCodecTX3G.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/XBMC.xcodeproj/project.pbxproj b/XBMC.xcodeproj/project.pbxproj index b110cf6e50..09c84293de 100644 --- a/XBMC.xcodeproj/project.pbxproj +++ b/XBMC.xcodeproj/project.pbxproj @@ -1817,6 +1817,8 @@ F5BDB81B1202032400F0B710 /* DVDSubtitleTagMicroDVD.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5BDB8191202032400F0B710 /* DVDSubtitleTagMicroDVD.cpp */; }; F5BDB820120203C200F0B710 /* AutoPtrHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5BDB81F120203C200F0B710 /* AutoPtrHandle.cpp */; }; F5BDB821120203C200F0B710 /* AutoPtrHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5BDB81F120203C200F0B710 /* AutoPtrHandle.cpp */; }; + F5CEE60913D3C89700225F72 /* DVDOverlayCodecTX3G.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5CEE60713D3C89700225F72 /* DVDOverlayCodecTX3G.cpp */; }; + F5CEE60A13D3C89700225F72 /* DVDOverlayCodecTX3G.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5CEE60713D3C89700225F72 /* DVDOverlayCodecTX3G.cpp */; }; F5D8D732102BB3B1004A11AB /* OverlayRendererGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5D8D72F102BB3B1004A11AB /* OverlayRendererGL.cpp */; }; F5D8D733102BB3B1004A11AB /* OverlayRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5D8D731102BB3B1004A11AB /* OverlayRenderer.cpp */; }; F5D8D734102BB3B1004A11AB /* OverlayRendererGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5D8D72F102BB3B1004A11AB /* OverlayRendererGL.cpp */; }; @@ -3777,6 +3779,8 @@ F5BDB8191202032400F0B710 /* DVDSubtitleTagMicroDVD.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DVDSubtitleTagMicroDVD.cpp; sourceTree = "<group>"; }; F5BDB81E120203C200F0B710 /* AutoPtrHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutoPtrHandle.h; sourceTree = "<group>"; }; F5BDB81F120203C200F0B710 /* AutoPtrHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AutoPtrHandle.cpp; sourceTree = "<group>"; }; + F5CEE60713D3C89700225F72 /* DVDOverlayCodecTX3G.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DVDOverlayCodecTX3G.cpp; sourceTree = "<group>"; }; + F5CEE60813D3C89700225F72 /* DVDOverlayCodecTX3G.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DVDOverlayCodecTX3G.h; sourceTree = "<group>"; }; F5D8D72E102BB3B1004A11AB /* OverlayRendererGL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OverlayRendererGL.h; sourceTree = "<group>"; }; F5D8D72F102BB3B1004A11AB /* OverlayRendererGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OverlayRendererGL.cpp; sourceTree = "<group>"; }; F5D8D730102BB3B1004A11AB /* OverlayRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OverlayRenderer.h; sourceTree = "<group>"; }; @@ -5241,6 +5245,8 @@ E38E152E0D25F9F900618676 /* DVDOverlayCodecFFmpeg.h */, E38E152F0D25F9F900618676 /* DVDOverlayCodecText.cpp */, E38E15300D25F9F900618676 /* DVDOverlayCodecText.h */, + F5CEE60713D3C89700225F72 /* DVDOverlayCodecTX3G.cpp */, + F5CEE60813D3C89700225F72 /* DVDOverlayCodecTX3G.h */, E38E15310D25F9F900618676 /* DVDOverlayImage.h */, E38E15320D25F9F900618676 /* DVDOverlaySpu.h */, E38E15330D25F9F900618676 /* DVDOverlayText.h */, @@ -8050,6 +8056,7 @@ 1830212813B8E2DC00770920 /* controledit.cpp in Sources */, DF27E26E13C23D12002514FE /* InertialScrollingHandler.cpp in Sources */, 18ECC96213CF178D00A9ED6C /* StreamUtils.cpp in Sources */, + F5CEE60913D3C89700225F72 /* DVDOverlayCodecTX3G.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -8943,6 +8950,7 @@ 1830212913B8E2DC00770920 /* controledit.cpp in Sources */, 43B0A5D013C64DF900B2382A /* InertialScrollingHandler.cpp in Sources */, 18ECC96313CF178D00A9ED6C /* StreamUtils.cpp in Sources */, + F5CEE60A13D3C89700225F72 /* DVDOverlayCodecTX3G.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/project/VS2010Express/XBMC.vcxproj b/project/VS2010Express/XBMC.vcxproj index eb2f1a2e06..5155fdcc0d 100644 --- a/project/VS2010Express/XBMC.vcxproj +++ b/project/VS2010Express/XBMC.vcxproj @@ -875,6 +875,7 @@ <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlayCodecFFmpeg.cpp" /> <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlayCodecSSA.cpp" /> <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlayCodecText.cpp" /> + <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlayCodecTX3G.cpp" /> <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\libspucc\cc_decoder.c"> <CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug (DirectX)|Win32'">CompileAsCpp</CompileAs> <CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug (OpenGL)|Win32'">CompileAsCpp</CompileAs> @@ -1732,6 +1733,7 @@ <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlayCodecFFmpeg.h" /> <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlayCodecSSA.h" /> <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlayCodecText.h" /> + <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlayCodecTX3G.h" /> <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlayImage.h" /> <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlaySpu.h" /> <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlaySSA.h" /> @@ -2064,4 +2066,4 @@ </VisualStudio> </ProjectExtensions> <Import Project="$(SolutionDir)\$(ProjectFileName).targets.user" Condition="Exists('$(SolutionDir)\$(ProjectFileName).targets.user')" /> -</Project>
\ No newline at end of file +</Project> diff --git a/project/VS2010Express/XBMC.vcxproj.filters b/project/VS2010Express/XBMC.vcxproj.filters index b642d952e4..8976fab60d 100644 --- a/project/VS2010Express/XBMC.vcxproj.filters +++ b/project/VS2010Express/XBMC.vcxproj.filters @@ -372,6 +372,9 @@ <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlayCodecText.cpp"> <Filter>cores\dvdplayer\DVDCodecs\Overlay</Filter> </ClCompile> + <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlayCodecTX3G.cpp"> + <Filter>cores\dvdplayer\DVDCodecs\Overlay</Filter> + </ClCompile> <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\libspucc\cc_decoder.c"> <Filter>cores\dvdplayer\DVDCodecs\Overlay\libspucc</Filter> </ClCompile> @@ -2640,6 +2643,9 @@ <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlayCodecText.h"> <Filter>cores\dvdplayer\DVDCodecs\Overlay</Filter> </ClInclude> + <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlayCodecTX3G.h"> + <Filter>cores\dvdplayer\DVDCodecs\Overlay</Filter> + </ClInclude> <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDCodecs\Overlay\DVDOverlayImage.h"> <Filter>cores\dvdplayer\DVDCodecs\Overlay</Filter> </ClInclude> @@ -4967,4 +4973,4 @@ <Filter>win32</Filter> </CustomBuild> </ItemGroup> -</Project>
\ No newline at end of file +</Project> diff --git a/xbmc/cores/dvdplayer/DVDCodecs/DVDFactoryCodec.cpp b/xbmc/cores/dvdplayer/DVDCodecs/DVDFactoryCodec.cpp index a3da6f130b..03f6dcc8ee 100644 --- a/xbmc/cores/dvdplayer/DVDCodecs/DVDFactoryCodec.cpp +++ b/xbmc/cores/dvdplayer/DVDCodecs/DVDFactoryCodec.cpp @@ -44,8 +44,10 @@ #include "Audio/DVDAudioCodecPassthroughFFmpeg.h" #include "Overlay/DVDOverlayCodecSSA.h" #include "Overlay/DVDOverlayCodecText.h" +#include "Overlay/DVDOverlayCodecTX3G.h" #include "Overlay/DVDOverlayCodecFFmpeg.h" + #include "DVDStreamInfo.h" #include "settings/GUISettings.h" #include "utils/SystemInfo.h" @@ -333,6 +335,10 @@ CDVDOverlayCodec* CDVDFactoryCodec::CreateOverlayCodec( CDVDStreamInfo &hint ) pCodec = OpenCodec(new CDVDOverlayCodecText(), hint, options); if( pCodec ) return pCodec; + case CODEC_ID_MOV_TEXT: + pCodec = OpenCodec(new CDVDOverlayCodecTX3G(), hint, options); + if( pCodec ) return pCodec; + default: pCodec = OpenCodec(new CDVDOverlayCodecFFmpeg(), hint, options); if( pCodec ) return pCodec; diff --git a/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecTX3G.cpp b/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecTX3G.cpp new file mode 100644 index 0000000000..56523cd081 --- /dev/null +++ b/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecTX3G.cpp @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2011 Team XBMC + * http://www.xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "system.h" +#include "DVDOverlayCodecTX3G.h" +#include "DVDOverlayText.h" +#include "DVDStreamInfo.h" +#include "utils/log.h" + +// 3GPP/TX3G (aka MPEG-4 Timed Text) Subtitle support +// 3GPP -> 3rd Generation Partnership Program +// adapted from https://trac.handbrake.fr/browser/trunk/libhb/dectx3gsub.c; + +// NOTE: None of these macros check for buffer overflow +#define READ_U8() *pos; pos += 1; +#define READ_U16() (pos[0] << 8) | pos[1]; pos += 2; +#define READ_U32() (pos[0] << 24) | (pos[1] << 16) | (pos[2] << 8) | pos[3]; pos += 4; +#define READ_ARRAY(n) pos; pos += n; +#define SKIP_ARRAY(n) pos += n; + +#define FOURCC(str) ((((uint32_t) str[0]) << 24) | \ + (((uint32_t) str[1]) << 16) | \ + (((uint32_t) str[2]) << 8) | \ + (((uint32_t) str[3]) << 0)) + +typedef enum { + BOLD = 0x1, + ITALIC = 0x2, + UNDERLINE = 0x4 +} FaceStyleFlag; + +// NOTE: indices in terms of *character* (not: byte) positions +typedef struct { + uint16_t bgnChar; + uint16_t endChar; + uint16_t fontID; + uint8_t faceStyleFlags; // FaceStyleFlag + uint8_t fontSize; + uint32_t textColorRGBA; +} StyleRecord; + +CDVDOverlayCodecTX3G::CDVDOverlayCodecTX3G() : CDVDOverlayCodec("TX3G Subtitle Decoder") +{ + m_pOverlay = NULL; +} + +CDVDOverlayCodecTX3G::~CDVDOverlayCodecTX3G() +{ + if (m_pOverlay) + SAFE_RELEASE(m_pOverlay); +} + +bool CDVDOverlayCodecTX3G::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options) +{ + if (hints.codec == CODEC_ID_MOV_TEXT) + return true; + return false; +} + +void CDVDOverlayCodecTX3G::Dispose() +{ + if (m_pOverlay) + SAFE_RELEASE(m_pOverlay); +} + +int CDVDOverlayCodecTX3G::Decode(BYTE* data, int size, double pts, double duration) +{ + if (m_pOverlay) + SAFE_RELEASE(m_pOverlay); + + m_pOverlay = new CDVDOverlayText(); + + // do not move this. READ_XXXX macros modify pos. + uint8_t *pos = data; + uint8_t *end = pos + size; + + // Parse the packet as a TX3G TextSample. + // Look for a single StyleBox ('styl') and + // read all contained StyleRecords. + // Ignore all other box types. + // NOTE: Buffer overflows on read are not checked. + // ALSO: READ_XXXX/SKIP_XXXX macros will modify pos. + uint16_t textLength = READ_U16(); + uint8_t *text = READ_ARRAY(textLength); + + int numStyleRecords = 0; + uint8_t *bgnStyle = (uint8_t*)calloc(textLength, 1); + uint8_t *endStyle = (uint8_t*)calloc(textLength, 1); + while (pos < end) + { + // Read TextSampleModifierBox + uint32_t size = READ_U32(); + if (size == 0) + size = pos - end; // extends to end of packet + if (size == 1) + { + CLog::Log(LOGDEBUG, "CDVDOverlayCodecTX3G: TextSampleModifierBox has unsupported large size" ); + break; + } + uint32_t type = READ_U32(); + if (type == FOURCC("uuid")) { + CLog::Log(LOGDEBUG, "CDVDOverlayCodecTX3G: TextSampleModifierBox has unsupported extended type" ); + break; + } + + if (type == FOURCC("styl")) + { + // Found a StyleBox. Parse the contained StyleRecords + if ( numStyleRecords != 0 ) + { + CLog::Log(LOGDEBUG, "CDVDOverlayCodecTX3G: found additional StyleBoxes on subtitle; skipping" ); + SKIP_ARRAY(size); + continue; + } + + numStyleRecords = READ_U16(); + for (int i = 0; i < numStyleRecords; i++) + { + StyleRecord curRecord; + curRecord.bgnChar = READ_U16(); + curRecord.endChar = READ_U16(); + curRecord.fontID = READ_U16(); + curRecord.faceStyleFlags = READ_U8(); + curRecord.fontSize = READ_U8(); + curRecord.textColorRGBA = READ_U32(); + + bgnStyle[curRecord.bgnChar] |= curRecord.faceStyleFlags; + endStyle[curRecord.endChar] |= curRecord.faceStyleFlags; + } + } + else + { + // Found some other kind of TextSampleModifierBox. Skip it. + SKIP_ARRAY(size); + } + } + + // Copy text to out and add HTML markup for the style records + int charIndex = 0; + CStdStringA strUTF8; + for (pos = text, end = text + textLength; pos < end; pos++) + { + if ((*pos & 0xC0) == 0x80) + { + // Is a non-first byte of a multi-byte UTF-8 character + strUTF8.append((const char*)pos, 1); + continue; // ...without incrementing 'charIndex' + } + + uint8_t bgnStyles = bgnStyle[charIndex]; + uint8_t endStyles = endStyle[charIndex]; + + // [B] or [/B] -> toggle bold on and off + // [I] or [/I] -> toggle italics on and off + // [COLOR ffab007f] or [/COLOR] -> toggle color on and off + // [CAPS <option>] or [/CAPS] -> toggle capatilization on and off + + if (endStyles & BOLD) + strUTF8.append("[/B]"); + if (endStyles & ITALIC) + strUTF8.append("[/I]"); + // we do not support underline + //if (endStyles & UNDERLINE) + // strUTF8.append("[/U]"); + + if (bgnStyles & BOLD) + strUTF8.append("[B]"); + if (bgnStyles & ITALIC) + strUTF8.append("[I]"); + // we do not support underline + //if (bgnStyles & UNDERLINE) + // strUTF8.append("[U]"); + + // stuff the UTF8 char + strUTF8.append((const char*)pos, 1); + + // this is a char index, not a byte index. + charIndex++; + } + + free(bgnStyle); + free(endStyle); + + if (strUTF8.IsEmpty()) + return OC_BUFFER; + + if (strUTF8[strUTF8.size()-1] == '\n') + strUTF8.Delete(strUTF8.size()-1); + + // add a new text element to our container + m_pOverlay->AddElement(new CDVDOverlayText::CElementText(strUTF8.c_str())); + + return OC_OVERLAY; +} + +void CDVDOverlayCodecTX3G::Reset() +{ + if (m_pOverlay) + SAFE_RELEASE(m_pOverlay); +} + +void CDVDOverlayCodecTX3G::Flush() +{ + if (m_pOverlay) + SAFE_RELEASE(m_pOverlay); +} + +CDVDOverlay* CDVDOverlayCodecTX3G::GetOverlay() +{ + if (m_pOverlay) + { + CDVDOverlay* overlay = m_pOverlay; + m_pOverlay = NULL; + return overlay; + } + return NULL; +} diff --git a/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecTX3G.h b/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecTX3G.h new file mode 100644 index 0000000000..d3c853064a --- /dev/null +++ b/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecTX3G.h @@ -0,0 +1,42 @@ +#pragma once + +/* + * Copyright (C) 2005-2008 Team XBMC + * http://www.xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "DVDOverlayCodec.h" + +class CDVDOverlayText; + +class CDVDOverlayCodecTX3G : public CDVDOverlayCodec +{ +public: + CDVDOverlayCodecTX3G(); + virtual ~CDVDOverlayCodecTX3G(); + virtual bool Open(CDVDStreamInfo &hints, CDVDCodecOptions &options); + virtual void Dispose(); + virtual int Decode(BYTE* data, int size, double pts, double duration); + virtual void Reset(); + virtual void Flush(); + virtual CDVDOverlay* GetOverlay(); + +private: + CDVDOverlayText* m_pOverlay; +}; diff --git a/xbmc/cores/dvdplayer/DVDCodecs/Overlay/Makefile.in b/xbmc/cores/dvdplayer/DVDCodecs/Overlay/Makefile.in index ac75e4b433..341fa38337 100644 --- a/xbmc/cores/dvdplayer/DVDCodecs/Overlay/Makefile.in +++ b/xbmc/cores/dvdplayer/DVDCodecs/Overlay/Makefile.in @@ -4,6 +4,7 @@ SRCS= DVDOverlayCodecCC.cpp \ DVDOverlayCodecFFmpeg.cpp \ DVDOverlayCodecSSA.cpp \ DVDOverlayCodecText.cpp \ + DVDOverlayCodecTX3G.cpp \ libspucc/cc_decoder.c \ LIB= Overlay.a |