├── sshpwd ├── scp ├── fonts ├── FreeSans.ttf └── FreeSansOblique.ttf ├── version.h ├── profiler.sh ├── omxplayer.h ├── Keyboard.h ├── gen_version.sh ├── linux ├── stat_utf8.h ├── stdio_utf8.h ├── PlatformInclude.h ├── XMemUtils.h ├── XSyncUtils.h ├── ConvUtils.h ├── RBP.cpp ├── RBP.h ├── XMemUtils.cpp └── XMemUtils.d ├── OMXOverlayCodecText.h ├── OMXThread.h ├── KeyConfig.h ├── OMXControl.h ├── Srt.h ├── cores └── IAudioCallback.h ├── RBP.h ├── utils ├── Clamp.h ├── SingleLock.h ├── LockBlock.h ├── log.h ├── Strprintf.h ├── RegExp.h ├── Enforce.h ├── Mailbox.h ├── ScopeExit.h ├── FunctorVisitor.h ├── PCMRemap.h ├── log.cpp └── RegExp.cpp ├── Subtitle.h ├── OMXStreamInfo.cpp ├── OMXSubtitleTagSami.h ├── Makefile.include ├── DynamicDll.cpp ├── OMXOverlay.h ├── OMXAudioCodecOMX.h ├── OMXStreamInfo.h ├── OMXOverlayCodec.h ├── Unicode.h ├── prepare-native-raspbian.sh ├── Makefile ├── Srt.cpp ├── File.h ├── dbuscontrol.sh ├── OMXOverlayText.h ├── OMXThread.cpp ├── omxplayer ├── OMXClock.h ├── OMXPlayerSync.h ├── OMXOverlayCodecText.cpp ├── OMXVideo.h ├── Unicode.cpp ├── guilib └── Geometry.h ├── Keyboard.cpp ├── File.cpp ├── OMXPlayerVideo.h ├── OMXPlayerAudio.h ├── DllOMX.h ├── OMXPlayerSubtitles.h ├── OMXAudio.h ├── DllSwResample.h ├── BitstreamConverter.h ├── KeyConfig.cpp ├── OMXReader.h └── SubtitleRenderer.h /sshpwd: -------------------------------------------------------------------------------- 1 | pi 2 | -------------------------------------------------------------------------------- /scp: -------------------------------------------------------------------------------- 1 | pi omxplayer.bin root@192.168.0.39:/usr/bin 2 | -------------------------------------------------------------------------------- /fonts/FreeSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ktrofimov/omxplayer-udpsync/HEAD/fonts/FreeSans.ttf -------------------------------------------------------------------------------- /fonts/FreeSansOblique.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ktrofimov/omxplayer-udpsync/HEAD/fonts/FreeSansOblique.ttf -------------------------------------------------------------------------------- /version.h: -------------------------------------------------------------------------------- 1 | #ifndef __VERSION_H__ 2 | #define __VERSION_H__ 3 | #define VERSION_DATE "Wed, 13 May 2015 23:17:49 +0400" 4 | #define VERSION_HASH "f322182" 5 | #define VERSION_BRANCH "master" 6 | #define VERSION_REPO "https://github.com/turingmachine/omxplayer.git" 7 | #endif 8 | -------------------------------------------------------------------------------- /profiler.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | insmod /lib/modules/3.1.10+/kernel/arch/arm/oprofile/oprofile.ko timer=1 4 | opcontrol --init 5 | opcontrol --vmlinux=/boot/vmlinux 6 | opcontrol --start 7 | 8 | ./omxplayer.bin -s -o hdmi /media/net/1080p/Gone\ in\ Sixty\ Seconds\ 2000.mkv 9 | 10 | opcontrol --dump 11 | opreport -l 12 | -------------------------------------------------------------------------------- /omxplayer.h: -------------------------------------------------------------------------------- 1 | #ifndef OMXPLAYER_H 2 | #define OMXPLAYER_H 3 | 4 | #define S(x) (int)(DVD_PLAYSPEED_NORMAL*(x)) 5 | 6 | void SetSpeed(int iSpeed); 7 | void JumpToPos( double Position ); 8 | void exitPlayer( void ); 9 | void fadeSound( void ); 10 | extern int playspeeds[]; 11 | extern int playspeed_current; 12 | extern const int playspeed_slow_min; 13 | extern const int playspeed_normal; 14 | extern bool m_is_sync_verbose; 15 | extern double stamp; 16 | 17 | #endif // #ifndef OMXPLAYER_H 18 | -------------------------------------------------------------------------------- /Keyboard.h: -------------------------------------------------------------------------------- 1 | #define OMXPLAYER_DBUS_PATH_SERVER "/org/mpris/MediaPlayer2" 2 | #define OMXPLAYER_DBUS_INTERFACE_ROOT "org.mpris.MediaPlayer2" 3 | #define OMXPLAYER_DBUS_INTERFACE_PLAYER "org.mpris.MediaPlayer2.Player" 4 | 5 | #include "OMXThread.h" 6 | #include 7 | 8 | class Keyboard : public OMXThread 9 | { 10 | protected: 11 | struct termios orig_termios; 12 | int orig_fl; 13 | DBusConnection *conn; 14 | std::map m_keymap; 15 | std::string m_dbus_name; 16 | public: 17 | Keyboard(); 18 | ~Keyboard(); 19 | void Close(); 20 | void Process(); 21 | void setKeymap(std::map keymap); 22 | void setDbusName(std::string dbus_name); 23 | void Sleep(unsigned int dwMilliSeconds); 24 | private: 25 | void restore_term(); 26 | void send_action(int action); 27 | int dbus_connect(); 28 | void dbus_disconnect(); 29 | }; -------------------------------------------------------------------------------- /gen_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Author: 4 | # Sergio Conde 5 | # 6 | # License: 7 | # This script is part of omxplayer and it should be 8 | # distributed under the same license. 9 | # 10 | 11 | date=$(date -R 2> /dev/null) 12 | hash="UNKNOWN" 13 | branch="UNKNOWN" 14 | repo="UNKNOWN" 15 | 16 | ref=$(git symbolic-ref -q HEAD 2> /dev/null) 17 | if [ x"$?" = x"0" ]; then 18 | hash=$(git rev-parse --short $ref 2> /dev/null) 19 | branch=${ref#refs/heads/} 20 | 21 | upstream=$(git for-each-ref --format='%(upstream:short)' $ref 2> /dev/null) 22 | if [ x"$upstream" != x"" ]; then 23 | repo=$(git config remote.${upstream%/$branch}.url) 24 | fi 25 | fi 26 | 27 | echo "#ifndef __VERSION_H__" 28 | echo "#define __VERSION_H__" 29 | echo "#define VERSION_DATE \"$date\"" 30 | echo "#define VERSION_HASH \"$hash\"" 31 | echo "#define VERSION_BRANCH \"$branch\"" 32 | echo "#define VERSION_REPO \"$repo\"" 33 | echo "#endif" 34 | -------------------------------------------------------------------------------- /linux/stat_utf8.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2011 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #ifndef STAT_UTF8_H__ 23 | #define STAT_UTF8_H__ 24 | 25 | #define stat64_utf8 stat64 26 | 27 | #endif //STAT_UTF8_H__ 28 | 29 | -------------------------------------------------------------------------------- /linux/stdio_utf8.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2011 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #ifndef STDIO_UTF8_H__ 23 | #define STDIO_UTF8_H__ 24 | 25 | #include 26 | 27 | #define remove_utf8 remove 28 | #define rename_utf8 rename 29 | #define fopen64_utf8 fopen 30 | 31 | #endif // STDIO_UTF8_H__ 32 | 33 | -------------------------------------------------------------------------------- /linux/PlatformInclude.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLATFORM_INCLUDE__H__ 2 | #define __PLATFORM_INCLUDE__H__ 3 | 4 | /* 5 | * Copyright (C) 2005-2008 Team XBMC 6 | * http://www.xbmc.org 7 | * 8 | * This Program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2, or (at your option) 11 | * any later version. 12 | * 13 | * This Program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with XBMC; see the file COPYING. If not, write to 20 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 21 | * http://www.gnu.org/copyleft/gpl.html 22 | * 23 | */ 24 | 25 | #include "PlatformDefs.h" 26 | #include "XHandlePublic.h" 27 | #include "XFileUtils.h" 28 | #include "XSyncUtils.h" 29 | #include "XEventUtils.h" 30 | #include "XTimeUtils.h" 31 | #include "XThreadUtils.h" 32 | #include "XMemUtils.h" 33 | #include "ConvUtils.h" 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /linux/XMemUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef __XMEMUTILS__H__ 2 | #define __XMEMUTILS__H__ 3 | 4 | /* 5 | * Copyright (C) 2005-2008 Team XBMC 6 | * http://www.xbmc.org 7 | * 8 | * This Program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2, or (at your option) 11 | * any later version. 12 | * 13 | * This Program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with XBMC; see the file COPYING. If not, write to 20 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 21 | * http://www.gnu.org/copyleft/gpl.html 22 | * 23 | */ 24 | 25 | // aligned memory allocation and free. memory returned will be aligned to "alignTo" bytes. 26 | // this is a linux (actually platfom free) implementation of the win32 CRT methods _aligned_malloc and _aligned_free. 27 | void *_aligned_malloc(size_t s, size_t alignTo); 28 | void _aligned_free(void *p) ; 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /OMXOverlayCodecText.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * Copyright (C) 2005-2008 Team XBMC 5 | * http://www.xbmc.org 6 | * 7 | * This Program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2, or (at your option) 10 | * any later version. 11 | * 12 | * This Program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with XBMC; see the file COPYING. If not, write to 19 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * http://www.gnu.org/copyleft/gpl.html 21 | * 22 | */ 23 | 24 | #include "OMXOverlayCodec.h" 25 | 26 | class COMXOverlayText; 27 | 28 | class COMXOverlayCodecText : public COMXOverlayCodec 29 | { 30 | public: 31 | COMXOverlayCodecText(); 32 | virtual ~COMXOverlayCodecText(); 33 | virtual bool Open(COMXStreamInfo &hints); 34 | virtual void Dispose(); 35 | virtual int Decode(BYTE* data, int size, double pts, double duration); 36 | virtual void Reset(); 37 | virtual void Flush(); 38 | virtual COMXOverlay* GetOverlay(); 39 | 40 | private: 41 | bool m_bIsSSA; 42 | COMXOverlayText* m_pOverlay; 43 | }; 44 | -------------------------------------------------------------------------------- /OMXThread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2008 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #ifndef _OMX_THREAD_H_ 23 | #define _OMX_THREAD_H_ 24 | 25 | #include 26 | 27 | class OMXThread 28 | { 29 | protected: 30 | pthread_attr_t m_tattr; 31 | struct sched_param m_sched_param; 32 | pthread_mutex_t m_lock; 33 | pthread_t m_thread; 34 | volatile bool m_running; 35 | volatile bool m_bStop; 36 | private: 37 | static void *Run(void *arg); 38 | public: 39 | OMXThread(); 40 | ~OMXThread(); 41 | bool Create(); 42 | virtual void Process() = 0; 43 | bool Running(); 44 | pthread_t ThreadHandle(); 45 | bool StopThread(); 46 | void Lock(); 47 | void UnLock(); 48 | }; 49 | #endif 50 | -------------------------------------------------------------------------------- /linux/XSyncUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef __X_SYNC_UTILS_ 2 | #define __X_SYNC_UTILS_ 3 | 4 | /* 5 | * Copyright (C) 2005-2008 Team XBMC 6 | * http://www.xbmc.org 7 | * 8 | * This Program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2, or (at your option) 11 | * any later version. 12 | * 13 | * This Program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with XBMC; see the file COPYING. If not, write to 20 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 21 | * http://www.gnu.org/copyleft/gpl.html 22 | * 23 | */ 24 | 25 | #include "PlatformDefs.h" 26 | #include "XHandlePublic.h" 27 | 28 | #ifdef TARGET_LINUX 29 | 30 | #define STATUS_WAIT_0 ((DWORD )0x00000000L) 31 | #define WAIT_FAILED ((DWORD)0xFFFFFFFF) 32 | #define WAIT_OBJECT_0 ((STATUS_WAIT_0 ) + 0 ) 33 | #define WAIT_TIMEOUT 258L 34 | #define INFINITE 0xFFFFFFFF 35 | #define STATUS_ABANDONED_WAIT_0 0x00000080 36 | #define WAIT_ABANDONED ((STATUS_ABANDONED_WAIT_0 ) + 0 ) 37 | #define WAIT_ABANDONED_0 ((STATUS_ABANDONED_WAIT_0 ) + 0 ) 38 | 39 | void GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer); 40 | 41 | #endif 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /linux/ConvUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef __CONV_UTILS__H__ 2 | #define __CONV_UTILS__H__ 3 | 4 | /* 5 | * Copyright (C) 2005-2008 Team XBMC 6 | * http://www.xbmc.org 7 | * 8 | * This Program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2, or (at your option) 11 | * any later version. 12 | * 13 | * This Program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with XBMC; see the file COPYING. If not, write to 20 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 21 | * http://www.gnu.org/copyleft/gpl.html 22 | * 23 | */ 24 | #include "PlatformDefs.h" // UINT DWORD LPCSTR LPSTR LPBOOL ... 25 | 26 | int WideCharToMultiByte( 27 | UINT CodePage, 28 | DWORD dwFlags, 29 | LPCWSTR lpWideCharStr, 30 | int cchWideChar, 31 | LPSTR lpMultiByteStr, 32 | int cbMultiByte, 33 | LPCSTR lpDefaultChar, 34 | LPBOOL lpUsedDefaultChar 35 | ); 36 | 37 | int MultiByteToWideChar( 38 | UINT CodePage, 39 | DWORD dwFlags, 40 | LPCSTR lpMultiByteStr, 41 | int cbMultiByte, 42 | LPWSTR lpWideCharStr, 43 | int cchWideChar 44 | ); 45 | 46 | 47 | DWORD GetLastError(); 48 | VOID SetLastError(DWORD dwErrCode); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /linux/RBP.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2009 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #include "RBP.h" 23 | #include "utils/log.h" 24 | 25 | #define CLASSNAME "CRBP" 26 | 27 | CRBP::CRBP() 28 | { 29 | m_initialized = false; 30 | m_DllBcmHost = new DllBcmHost(); 31 | } 32 | 33 | CRBP::~CRBP() 34 | { 35 | Deinitialize(); 36 | delete m_DllBcmHost; 37 | } 38 | 39 | bool CRBP::Initialize() 40 | { 41 | m_initialized = m_DllBcmHost->Load(); 42 | if(!m_initialized) 43 | return false; 44 | 45 | m_DllBcmHost->bcm_host_init(); 46 | 47 | return true; 48 | } 49 | 50 | void CRBP::Deinitialize() 51 | { 52 | m_DllBcmHost->bcm_host_deinit(); 53 | 54 | if(m_initialized) 55 | m_DllBcmHost->Unload(); 56 | 57 | m_initialized = false; 58 | } 59 | -------------------------------------------------------------------------------- /KeyConfig.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | class KeyConfig 5 | { 6 | 7 | public: 8 | enum 9 | { 10 | ACTION_DECREASE_SPEED = 1, 11 | ACTION_INCREASE_SPEED = 2, 12 | ACTION_REWIND = 3, 13 | ACTION_FAST_FORWARD = 4, 14 | ACTION_SHOW_INFO = 5, 15 | ACTION_PREVIOUS_AUDIO = 6, 16 | ACTION_NEXT_AUDIO = 7, 17 | ACTION_PREVIOUS_CHAPTER = 8, 18 | ACTION_NEXT_CHAPTER = 9, 19 | ACTION_PREVIOUS_SUBTITLE = 10, 20 | ACTION_NEXT_SUBTITLE = 11, 21 | ACTION_TOGGLE_SUBTITLE = 12, 22 | ACTION_DECREASE_SUBTITLE_DELAY = 13, 23 | ACTION_INCREASE_SUBTITLE_DELAY = 14, 24 | ACTION_EXIT = 15, 25 | ACTION_PAUSE = 16, 26 | ACTION_DECREASE_VOLUME = 17, 27 | ACTION_INCREASE_VOLUME = 18, 28 | ACTION_SEEK_BACK_SMALL = 19, 29 | ACTION_SEEK_FORWARD_SMALL = 20, 30 | ACTION_SEEK_BACK_LARGE = 21, 31 | ACTION_SEEK_FORWARD_LARGE = 22, 32 | ACTION_SEEK_RELATIVE = 25, 33 | ACTION_SEEK_ABSOLUTE = 26, 34 | ACTION_STEP = 23, 35 | ACTION_BLANK = 24, 36 | ACTION_MOVE_VIDEO = 27, 37 | ACTION_HIDE_VIDEO = 28, 38 | ACTION_UNHIDE_VIDEO = 29, 39 | ACTION_SHOW = 30, 40 | ACTION_BLUR = 31 41 | }; 42 | 43 | #define KEY_LEFT 0x5b44 44 | #define KEY_RIGHT 0x5b43 45 | #define KEY_UP 0x5b41 46 | #define KEY_DOWN 0x5b42 47 | #define KEY_ESC 27 48 | 49 | static std::map buildDefaultKeymap(); 50 | static std::map parseConfigFile(std::string filepath); 51 | }; 52 | -------------------------------------------------------------------------------- /OMXControl.h: -------------------------------------------------------------------------------- 1 | #define OMXPLAYER_DBUS_PATH_SERVER "/org/mpris/MediaPlayer2" 2 | #define OMXPLAYER_DBUS_INTERFACE_ROOT "org.mpris.MediaPlayer2" 3 | #define OMXPLAYER_DBUS_INTERFACE_PLAYER "org.mpris.MediaPlayer2.Player" 4 | 5 | #include 6 | #include "OMXClock.h" 7 | #include "OMXPlayerAudio.h" 8 | #include "OMXPlayerSubtitles.h" 9 | 10 | class OMXControlResult { 11 | int key; 12 | int64_t arg; 13 | const char *winarg; 14 | 15 | public: 16 | OMXControlResult(int); 17 | OMXControlResult(int, int64_t); 18 | OMXControlResult(int, const char *); 19 | int getKey(); 20 | int64_t getArg(); 21 | const char *getWinArg(); 22 | }; 23 | 24 | class OMXControl 25 | { 26 | protected: 27 | DBusConnection *bus; 28 | OMXClock *clock; 29 | OMXPlayerAudio *audio; 30 | OMXReader *reader; 31 | OMXPlayerSubtitles *subtitles; 32 | public: 33 | OMXControl(); 34 | ~OMXControl(); 35 | void init(OMXClock *m_av_clock, OMXPlayerAudio *m_player_audio, OMXPlayerSubtitles *m_player_subtitles, OMXReader *m_omx_reader, std::string& dbus_name); 36 | OMXControlResult getEvent(); 37 | void dispatch(); 38 | private: 39 | int dbus_connect(std::string& dbus_name); 40 | void dbus_disconnect(); 41 | DBusHandlerResult dbus_respond_ok(DBusMessage *m); 42 | DBusHandlerResult dbus_respond_int64(DBusMessage *m, int64_t i); 43 | DBusHandlerResult dbus_respond_double(DBusMessage *m, double d); 44 | DBusHandlerResult dbus_respond_boolean(DBusMessage *m, int b); 45 | DBusHandlerResult dbus_respond_string(DBusMessage *m, const char *text); 46 | DBusHandlerResult dbus_respond_array(DBusMessage *m, const char *array[], int size); 47 | }; 48 | -------------------------------------------------------------------------------- /linux/RBP.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | * Copyright (C) 2005-2009 Team XBMC 4 | * http://www.xbmc.org 5 | * 6 | * This Program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2, or (at your option) 9 | * any later version. 10 | * 11 | * This Program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with XBMC; see the file COPYING. If not, write to 18 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 19 | * http://www.gnu.org/copyleft/gpl.html 20 | * 21 | */ 22 | 23 | /* 24 | #define _HAVE_SBRK 1 25 | #define HAVE_CMAKE_CONFIG 1 26 | #define _REENTRANT 1 27 | #ifndef VCHI_BULK_ALIGN 28 | #define VCHI_BULK_ALIGN 1 29 | #endif 30 | #ifndef VCHI_BULK_GRANULARITY 31 | #define VCHI_BULK_GRANULARITY 1 32 | #endif 33 | */ 34 | //#define OMX_SKIP64BIT 35 | #ifndef USE_VCHIQ_ARM 36 | #define USE_VCHIQ_ARM 37 | #endif 38 | #ifndef __VIDEOCORE4__ 39 | #define __VIDEOCORE4__ 40 | #endif 41 | #ifndef HAVE_VMCS_CONFIG 42 | #define HAVE_VMCS_CONFIG 43 | #endif 44 | 45 | #include "DllBCM.h" 46 | 47 | class CRBP 48 | { 49 | public: 50 | CRBP(); 51 | ~CRBP(); 52 | 53 | bool Initialize(); 54 | void Deinitialize(); 55 | 56 | private: 57 | DllBcmHost *m_DllBcmHost; 58 | bool m_initialized; 59 | }; 60 | 61 | extern CRBP g_RBP; 62 | -------------------------------------------------------------------------------- /Srt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Author: Torarin Hals Bakke (2012) 4 | 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | 29 | #include 30 | #include 31 | 32 | #include "Subtitle.h" 33 | 34 | bool ReadSrt(const std::string& filename, std::vector& subtitles); 35 | -------------------------------------------------------------------------------- /cores/IAudioCallback.h: -------------------------------------------------------------------------------- 1 | // IAudioCallback.h: interface for the IAudioCallback class. 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | 5 | #if !defined(AFX_IAUDIOCALLBACK_H__5A6AC7CF_C60E_45B9_8113_599F036FBBF8__INCLUDED_) 6 | #define AFX_IAUDIOCALLBACK_H__5A6AC7CF_C60E_45B9_8113_599F036FBBF8__INCLUDED_ 7 | 8 | /* 9 | * Copyright (C) 2005-2008 Team XBMC 10 | * http://www.xbmc.org 11 | * 12 | * This Program is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2, or (at your option) 15 | * any later version. 16 | * 17 | * This Program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with XBMC; see the file COPYING. If not, write to 24 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 25 | * http://www.gnu.org/copyleft/gpl.html 26 | * 27 | */ 28 | 29 | #if _MSC_VER > 1000 30 | #pragma once 31 | #endif // _MSC_VER > 1000 32 | 33 | class IAudioCallback 34 | { 35 | public: 36 | IAudioCallback() {}; 37 | virtual ~IAudioCallback() {}; 38 | virtual void OnInitialize(int iChannels, int iSamplesPerSec, int iBitsPerSample) = 0; 39 | virtual void OnAudioData(const unsigned char* pAudioData, int iAudioDataLength) = 0; 40 | 41 | }; 42 | 43 | #endif // !defined(AFX_IAUDIOCALLBACK_H__5A6AC7CF_C60E_45B9_8113_599F036FBBF8__INCLUDED_) 44 | -------------------------------------------------------------------------------- /RBP.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | * Copyright (C) 2005-2009 Team XBMC 4 | * http://www.xbmc.org 5 | * 6 | * This Program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2, or (at your option) 9 | * any later version. 10 | * 11 | * This Program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with XBMC; see the file COPYING. If not, write to 18 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 19 | * http://www.gnu.org/copyleft/gpl.html 20 | * 21 | */ 22 | 23 | /* 24 | #define _HAVE_SBRK 1 25 | #define HAVE_CMAKE_CONFIG 1 26 | #define _REENTRANT 1 27 | #ifndef VCHI_BULK_ALIGN 28 | #define VCHI_BULK_ALIGN 1 29 | #endif 30 | #ifndef VCHI_BULK_GRANULARITY 31 | #define VCHI_BULK_GRANULARITY 1 32 | #endif 33 | */ 34 | //#define OMX_SKIP64BIT 35 | #ifndef USE_VCHIQ_ARM 36 | #define USE_VCHIQ_ARM 37 | #endif 38 | #ifndef __VIDEOCORE4__ 39 | #define __VIDEOCORE4__ 40 | #endif 41 | #ifndef HAVE_VMCS_CONFIG 42 | #define HAVE_VMCS_CONFIG 43 | #endif 44 | 45 | #ifndef HAVE_LIBBCM_HOST 46 | #define HAVE_LIBBCM_HOST 47 | #endif 48 | 49 | #include "DllBCM.h" 50 | 51 | class CRBP 52 | { 53 | public: 54 | CRBP(); 55 | ~CRBP(); 56 | 57 | bool Initialize(); 58 | void Deinitialize(); 59 | 60 | private: 61 | DllBcmHost *m_DllBcmHost; 62 | bool m_initialized; 63 | }; 64 | 65 | extern CRBP g_RBP; 66 | -------------------------------------------------------------------------------- /utils/Clamp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Author: Torarin Hals Bakke (2012) 4 | 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | 29 | template 30 | T clamp(T val, T lo, T hi) { 31 | return val < lo ? lo : hi < val ? hi : val; 32 | } 33 | 34 | template 35 | void procrustes(T& val, U cap) { 36 | if (cap < val) val = cap; 37 | } 38 | -------------------------------------------------------------------------------- /linux/XMemUtils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* 6 | * Copyright (C) 2005-2008 Team XBMC 7 | * http://www.xbmc.org 8 | * 9 | * This Program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2, or (at your option) 12 | * any later version. 13 | * 14 | * This Program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with XBMC; see the file COPYING. If not, write to 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * http://www.gnu.org/copyleft/gpl.html 23 | * 24 | */ 25 | 26 | #include "XMemUtils.h" 27 | 28 | #undef ALIGN 29 | #define ALIGN(value, alignment) (((value)+(alignment-1))&~(alignment-1)) 30 | 31 | // aligned memory allocation. 32 | // in order to do so - we alloc extra space and store the original allocation in it (so that we can free later on). 33 | // the returned address will be the nearest alligned address within the space allocated. 34 | void *_aligned_malloc(size_t s, size_t alignTo) { 35 | 36 | char *pFull = (char*)malloc(s + alignTo + sizeof(char *)); 37 | char *pAlligned = (char *)ALIGN(((unsigned long)pFull + sizeof(char *)), alignTo); 38 | 39 | *(char **)(pAlligned - sizeof(char*)) = pFull; 40 | 41 | return(pAlligned); 42 | } 43 | 44 | void _aligned_free(void *p) { 45 | if (!p) 46 | return; 47 | 48 | char *pFull = *(char **)(((char *)p) - sizeof(char *)); 49 | free(pFull); 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /Subtitle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Author: Torarin Hals Bakke (2012) 4 | 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | struct Subtitle { 34 | template 35 | Subtitle(int start, int stop, T&& text_lines) 36 | : start(start), 37 | stop(stop), 38 | text_lines(std::forward(text_lines)) 39 | {} 40 | 41 | int start; 42 | int stop; 43 | std::vector text_lines; 44 | }; 45 | -------------------------------------------------------------------------------- /utils/SingleLock.h: -------------------------------------------------------------------------------- 1 | // SingleLock.h: interface for the CSingleLock class. 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | 5 | /* 6 | * XBMC Media Center 7 | * Copyright (c) 2002 Frodo 8 | * Portions Copyright (c) by the authors of ffmpeg and xvid 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include 28 | 29 | class CCriticalSection 30 | { 31 | public: 32 | inline CCriticalSection() 33 | { 34 | pthread_mutexattr_t mta; 35 | pthread_mutexattr_init(&mta); 36 | pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE); 37 | pthread_mutex_init(&m_lock, &mta); 38 | } 39 | inline ~CCriticalSection() { pthread_mutex_destroy(&m_lock); } 40 | inline void Lock() { pthread_mutex_lock(&m_lock); } 41 | inline void Unlock() { pthread_mutex_unlock(&m_lock); } 42 | 43 | protected: 44 | pthread_mutex_t m_lock; 45 | }; 46 | 47 | 48 | class CSingleLock 49 | { 50 | public: 51 | inline CSingleLock(CCriticalSection& cs) { m_section = cs; m_section.Lock(); } 52 | inline ~CSingleLock() { m_section.Unlock(); } 53 | 54 | protected: 55 | CCriticalSection m_section; 56 | }; 57 | 58 | 59 | -------------------------------------------------------------------------------- /OMXStreamInfo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2008 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #include "OMXStreamInfo.h" 23 | 24 | COMXStreamInfo::COMXStreamInfo() 25 | { 26 | extradata = NULL; 27 | Clear(); 28 | } 29 | 30 | COMXStreamInfo::~COMXStreamInfo() 31 | { 32 | //if( extradata && extrasize ) free(extradata); 33 | 34 | extradata = NULL; 35 | extrasize = 0; 36 | } 37 | 38 | 39 | void COMXStreamInfo::Clear() 40 | { 41 | codec = CODEC_ID_NONE; 42 | software = false; 43 | codec_tag = 0; 44 | 45 | //if( extradata && extrasize ) free(extradata); 46 | 47 | extradata = NULL; 48 | extrasize = 0; 49 | 50 | fpsscale = 0; 51 | fpsrate = 0; 52 | height = 0; 53 | width = 0; 54 | aspect = 0.0; 55 | vfr = false; 56 | stills = false; 57 | level = 0; 58 | profile = 0; 59 | ptsinvalid = false; 60 | 61 | channels = 0; 62 | samplerate = 0; 63 | blockalign = 0; 64 | bitrate = 0; 65 | bitspersample = 0; 66 | 67 | identifier = 0; 68 | 69 | framesize = 0; 70 | syncword = 0; 71 | } 72 | -------------------------------------------------------------------------------- /utils/LockBlock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Author: Torarin Hals Bakke (2012) 4 | 5 | // Usage: 6 | // LOCK_BLOCK(mutex) { 7 | // ... 8 | // } 9 | // or 10 | // LOCK_BLOCK(mutex) 11 | // ...; 12 | 13 | // Boost Software License - Version 1.0 - August 17th, 2003 14 | 15 | // Permission is hereby granted, free of charge, to any person or organization 16 | // obtaining a copy of the software and accompanying documentation covered by 17 | // this license (the "Software") to use, reproduce, display, distribute, 18 | // execute, and transmit the Software, and to prepare derivative works of the 19 | // Software, and to permit third-parties to whom the Software is furnished to 20 | // do so, all subject to the following: 21 | 22 | // The copyright notices in the Software and this entire statement, including 23 | // the above license grant, this restriction and the following disclaimer, 24 | // must be included in all copies of the Software, in whole or in part, and 25 | // all derivative works of the Software, unless such copies or derivative 26 | // works are solely in the form of machine-executable object code generated by 27 | // a source language processor. 28 | 29 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 32 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 33 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 34 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 35 | // DEALINGS IN THE SOFTWARE. 36 | 37 | #include 38 | 39 | template 40 | struct Lock_block { 41 | Lock_block(T& mutex): lock(mutex) {} 42 | operator bool() {return true;} 43 | std::lock_guard lock; 44 | }; 45 | 46 | #define LOCK_BLOCK(mutex) \ 47 | if (Lock_block LOCK_BLOCK_cond{mutex}) 48 | -------------------------------------------------------------------------------- /OMXSubtitleTagSami.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * Copyright (C) 2005-2008 Team XBMC 5 | * http://www.xbmc.org 6 | * 7 | * This Program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2, or (at your option) 10 | * any later version. 11 | * 12 | * This Program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with XBMC; see the file COPYING. If not, write to 19 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * http://www.gnu.org/copyleft/gpl.html 21 | * 22 | */ 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | #define FLAG_BOLD 0 29 | #define FLAG_ITALIC 1 30 | #define FLAG_COLOR 2 31 | #define FLAG_LANGUAGE 3 32 | 33 | class COMXOverlayText; 34 | class CDVDSubtitleStream; 35 | class CRegExp; 36 | 37 | class COMXSubtitleTagSami 38 | { 39 | public: 40 | COMXSubtitleTagSami() 41 | { 42 | m_tags = NULL; 43 | m_tagOptions = NULL; 44 | m_flag[FLAG_BOLD] = false; 45 | m_flag[FLAG_ITALIC] = false; 46 | m_flag[FLAG_COLOR] = false; 47 | m_flag[FLAG_LANGUAGE] = false; //set to true when classID != lang 48 | } 49 | virtual ~COMXSubtitleTagSami(); 50 | bool Init(); 51 | void ConvertLine(COMXOverlayText* pOverlay, const char* line, int len, const char* lang = NULL); 52 | void CloseTag(COMXOverlayText* pOverlay); 53 | //void LoadHead(CDVDSubtitleStream* samiStream); 54 | 55 | typedef struct 56 | { 57 | std::string ID; 58 | std::string Name; 59 | std::string Lang; 60 | std::string SAMIType; 61 | } SLangclass; 62 | 63 | std::vector m_Langclass; 64 | 65 | private: 66 | CRegExp *m_tags; 67 | CRegExp *m_tagOptions; 68 | bool m_flag[4]; 69 | }; 70 | 71 | -------------------------------------------------------------------------------- /Makefile.include: -------------------------------------------------------------------------------- 1 | USE_BUILDROOT=0 2 | FLOAT=hard 3 | 4 | ifeq ($(USE_BUILDROOT), 1) 5 | BUILDROOT :=/opt/xbmc-bcm/buildroot 6 | SDKSTAGE :=$(BUILDROOT)/output/staging 7 | TARGETFS :=$(BUILDROOT)/output/target 8 | TOOLCHAIN :=$(BUILDROOT)/output/host/usr/ 9 | HOST :=arm-unknown-linux-gnueabi 10 | SYSROOT :=$(BUILDROOT)/output/host/usr/arm-unknown-linux-gnueabi/sysroot 11 | else 12 | BUILDROOT :=/opt/bcm-rootfs 13 | SDKSTAGE :=/opt/bcm-rootfs 14 | TARGETFS :=/opt/bcm-rootfs 15 | TOOLCHAIN :=/home/adl/src/RPi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian 16 | HOST :=arm-linux-gnueabihf 17 | #SYSROOT :=$(TOOLCHAIN)/arm-bcm2708hardfp-linux-gnueabi/sysroot 18 | SYSROOT :=/opt/bcm-rootfs 19 | endif 20 | 21 | JOBS=7 22 | 23 | CFLAGS := -isystem$(PREFIX)/include 24 | CXXFLAGS := $(CFLAGS) 25 | CPPFLAGS := $(CFLAGS) 26 | LDFLAGS := -L$(BUILDROOT)/lib 27 | LD := $(TOOLCHAIN)/bin/$(HOST)-ld --sysroot=$(SYSROOT) 28 | CC := $(TOOLCHAIN)/bin/$(HOST)-gcc --sysroot=$(SYSROOT) 29 | CXX := $(TOOLCHAIN)/bin/$(HOST)-g++ --sysroot=$(SYSROOT) 30 | OBJDUMP := $(TOOLCHAIN)/bin/$(HOST)-objdump 31 | RANLIB := $(TOOLCHAIN)/bin/$(HOST)-ranlib 32 | STRIP := $(TOOLCHAIN)/bin/$(HOST)-strip 33 | AR := $(TOOLCHAIN)/bin/$(HOST)-ar 34 | CXXCP := $(CXX) -E 35 | PATH := $(PREFIX)/bin:$(BUILDROOT)/output/host/usr/bin:$(PATH) 36 | 37 | CFLAGS += -pipe -mfloat-abi=$(FLOAT) -mcpu=arm1176jzf-s -fomit-frame-pointer -mabi=aapcs-linux -mtune=arm1176jzf-s -mfpu=vfp -Wno-psabi -mno-apcs-stack-check -g -mstructure-size-boundary=32 -mno-sched-prolog 38 | LDFLAGS += -L$(SDKSTAGE)/lib -L$(SDKSTAGE)/usr/lib -L$(SDKSTAGE)/opt/vc/lib/ -Lpcre/build 39 | #INCLUDES += -isystem$(SDKSTAGE)/usr/include -isystem$(SDKSTAGE)/opt/vc/include -isystem$(SYSROOT)/usr/include -isystem$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads -isystem$(SDKSTAGE)/usr/include/freetype2 40 | INCLUDES += -isystem$(SDKSTAGE)/opt/vc/include \ 41 | -isystem$(SYSROOT)/usr/include \ 42 | -isystem$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads \ 43 | -Ipcre/build \ 44 | -Iboost-trunk \ 45 | -Ifreetype2/include \ 46 | -isystem$(SYSROOT)/usr/include/dbus-1.0 \ 47 | -isystem$(SYSROOT)/usr/lib/$(HOST)/dbus/include -------------------------------------------------------------------------------- /utils/log.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * Copyright (C) 2005-2008 Team XBMC 5 | * http://www.xbmc.org 6 | * 7 | * This Program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2, or (at your option) 10 | * any later version. 11 | * 12 | * This Program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with XBMC; see the file COPYING. If not, write to 19 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * http://www.gnu.org/copyleft/gpl.html 21 | * 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | #define LOG_LEVEL_NONE -1 // nothing at all is logged 28 | #define LOG_LEVEL_NORMAL 0 // shows notice, error, severe and fatal 29 | #define LOG_LEVEL_DEBUG 1 // shows all 30 | #define LOG_LEVEL_DEBUG_FREEMEM 2 // shows all + shows freemem on screen 31 | #define LOG_LEVEL_DEBUG_SAMBA 3 // shows all + freemem on screen + samba debugging 32 | #define LOG_LEVEL_MAX LOG_LEVEL_DEBUG_SAMBA 33 | 34 | // ones we use in the code 35 | #define LOGDEBUG 0 36 | #define LOGINFO 1 37 | #define LOGNOTICE 2 38 | #define LOGWARNING 3 39 | #define LOGERROR 4 40 | #define LOGSEVERE 5 41 | #define LOGFATAL 6 42 | #define LOGNONE 7 43 | 44 | #ifdef __GNUC__ 45 | #define ATTRIB_LOG_FORMAT __attribute__((format(printf,2,3))) 46 | #else 47 | #define ATTRIB_LOG_FORMAT 48 | #endif 49 | 50 | class CLog 51 | { 52 | public: 53 | CLog(); 54 | virtual ~CLog(void); 55 | static void Close(); 56 | static void Log(int loglevel, const char *format, ... ) ATTRIB_LOG_FORMAT; 57 | static void MemDump(char *pData, int length); 58 | static bool Init(const char* path); 59 | static void SetLogLevel(int level); 60 | static int GetLogLevel(); 61 | private: 62 | static void OutputDebugString(const std::string& line); 63 | }; 64 | -------------------------------------------------------------------------------- /DynamicDll.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2008 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #include "DynamicDll.h" 23 | #include "utils/log.h" 24 | 25 | DllDynamic::DllDynamic() 26 | { 27 | m_dll=NULL; 28 | m_DelayUnload=true; 29 | } 30 | 31 | DllDynamic::DllDynamic(const CStdString& strDllName) 32 | { 33 | m_strDllName=strDllName; 34 | m_dll=NULL; 35 | m_DelayUnload=true; 36 | } 37 | 38 | DllDynamic::~DllDynamic() 39 | { 40 | Unload(); 41 | } 42 | 43 | bool DllDynamic::Load() 44 | { 45 | if (m_dll) 46 | return true; 47 | 48 | /* 49 | if (!(m_dll=CSectionLoader::LoadDLL(m_strDllName, m_DelayUnload, LoadSymbols()))) 50 | return false; 51 | 52 | if (!ResolveExports()) 53 | { 54 | CLog::Log(LOGERROR, "Unable to resolve exports from dll %s", m_strDllName.c_str()); 55 | Unload(); 56 | return false; 57 | } 58 | */ 59 | 60 | return true; 61 | } 62 | 63 | void DllDynamic::Unload() 64 | { 65 | /* 66 | if(m_dll) 67 | CSectionLoader::UnloadDLL(m_strDllName); 68 | */ 69 | m_dll=NULL; 70 | } 71 | 72 | bool DllDynamic::CanLoad() 73 | { 74 | return true; 75 | } 76 | 77 | bool DllDynamic::EnableDelayedUnload(bool bOnOff) 78 | { 79 | if (m_dll) 80 | return false; 81 | 82 | m_DelayUnload=bOnOff; 83 | 84 | return true; 85 | } 86 | 87 | bool DllDynamic::SetFile(const CStdString& strDllName) 88 | { 89 | if (m_dll) 90 | return false; 91 | 92 | m_strDllName=strDllName; 93 | return true; 94 | } 95 | 96 | -------------------------------------------------------------------------------- /OMXOverlay.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * Copyright (C) 2006-2010 Team XBMC 5 | * http://www.xbmc.org 6 | * 7 | * This Program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2, or (at your option) 10 | * any later version. 11 | * 12 | * This Program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with XBMC; see the file COPYING. If not, write to 19 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * http://www.gnu.org/copyleft/gpl.html 21 | * 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | enum OMXOverlayType 29 | { 30 | OMXOVERLAY_TYPE_NONE = -1, 31 | OMXOVERLAY_TYPE_SPU = 1, 32 | OMXOVERLAY_TYPE_TEXT = 2, 33 | OMXOVERLAY_TYPE_IMAGE = 3, 34 | OMXOVERLAY_TYPE_SSA = 4 35 | }; 36 | 37 | class COMXOverlay 38 | { 39 | public: 40 | COMXOverlay(OMXOverlayType type) 41 | { 42 | m_type = type; 43 | 44 | iPTSStartTime = 0LL; 45 | iPTSStopTime = 0LL; 46 | bForced = false; 47 | replace = false; 48 | 49 | iGroupId = 0; 50 | } 51 | 52 | COMXOverlay(const COMXOverlay& src) 53 | { 54 | m_type = src.m_type; 55 | iPTSStartTime = src.iPTSStartTime; 56 | iPTSStopTime = src.iPTSStopTime; 57 | bForced = src.bForced; 58 | replace = src.replace; 59 | iGroupId = src.iGroupId; 60 | } 61 | 62 | virtual ~COMXOverlay() 63 | { 64 | } 65 | 66 | bool IsOverlayType(OMXOverlayType type) { return (m_type == type); } 67 | 68 | double iPTSStartTime; 69 | double iPTSStopTime; 70 | bool bForced; // display, no matter what 71 | bool replace; // replace by next nomatter what stoptime it has 72 | int iGroupId; 73 | protected: 74 | OMXOverlayType m_type; 75 | }; 76 | 77 | typedef std::vector VecOMXOverlays; 78 | typedef std::vector::iterator VecOMXOverlaysIter; 79 | -------------------------------------------------------------------------------- /OMXAudioCodecOMX.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * Copyright (C) 2005-2008 Team XBMC 5 | * http://www.xbmc.org 6 | * 7 | * This Program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2, or (at your option) 10 | * any later version. 11 | * 12 | * This Program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with XBMC; see the file COPYING. If not, write to 19 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * http://www.gnu.org/copyleft/gpl.html 21 | * 22 | */ 23 | 24 | #include "DllAvCodec.h" 25 | #include "DllAvFormat.h" 26 | #include "DllAvUtil.h" 27 | #include "DllSwResample.h" 28 | 29 | #include "OMXStreamInfo.h" 30 | #include "utils/PCMRemap.h" 31 | #include "linux/PlatformDefs.h" 32 | 33 | class COMXAudioCodecOMX 34 | { 35 | public: 36 | COMXAudioCodecOMX(); 37 | ~COMXAudioCodecOMX(); 38 | bool Open(COMXStreamInfo &hints); 39 | void Dispose(); 40 | int Decode(BYTE* pData, int iSize, double dts, double pts); 41 | int GetData(BYTE** dst, double &dts, double &pts); 42 | void Reset(); 43 | int GetChannels(); 44 | uint64_t GetChannelMap(); 45 | int GetSampleRate(); 46 | int GetBitsPerSample(); 47 | static const char* GetName() { return "FFmpeg"; } 48 | int GetBitRate(); 49 | unsigned int GetFrameSize() { return m_frameSize; } 50 | 51 | protected: 52 | AVCodecContext* m_pCodecContext; 53 | SwrContext* m_pConvert; 54 | enum AVSampleFormat m_iSampleFormat; 55 | enum AVSampleFormat m_desiredSampleFormat; 56 | 57 | AVFrame* m_pFrame1; 58 | 59 | BYTE *m_pBufferOutput; 60 | int m_iBufferOutputUsed; 61 | int m_iBufferOutputAlloced; 62 | 63 | bool m_bOpenedCodec; 64 | 65 | int m_channels; 66 | 67 | bool m_bFirstFrame; 68 | bool m_bGotFrame; 69 | bool m_bNoConcatenate; 70 | unsigned int m_frameSize; 71 | double m_dts, m_pts; 72 | DllAvCodec m_dllAvCodec; 73 | DllAvUtil m_dllAvUtil; 74 | DllSwResample m_dllSwResample; 75 | }; 76 | -------------------------------------------------------------------------------- /utils/Strprintf.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Author: Torarin Hals Bakke (2013) 4 | 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | template 34 | std::string strprintf_impl(const char (&format)[N], Ts... ts) { 35 | const auto length_guess = static_cast(1.5 * (N - 1 /* '\0' */) + 0.5); 36 | std::string result; 37 | result.resize(length_guess); 38 | auto formatted_length = 39 | snprintf(&result[0], length_guess + 1 /* '\0' */, &format[0], ts...); 40 | assert(formatted_length >= 0); 41 | result.resize(formatted_length); 42 | if ((unsigned) formatted_length > length_guess) { 43 | auto snprintf_ret = 44 | snprintf(&result[0], formatted_length + 1 /* '\0' */, &format[0], ts...); 45 | assert(snprintf_ret >= 0); 46 | } 47 | return result; 48 | } 49 | 50 | int strprintf_arg_checker(const char* format, ...) __attribute__((format(printf, 1, 2))); 51 | 52 | #define strprintf(format, ts...) \ 53 | ((void) sizeof(strprintf_arg_checker(format, ts)), strprintf_impl(format, ts)) 54 | -------------------------------------------------------------------------------- /OMXStreamInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2008 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #if (defined HAVE_CONFIG_H) && (!defined WIN32) 25 | #include "config.h" 26 | #endif 27 | #ifndef TARGET_LINUX 28 | enum AVCodecID; 29 | #else 30 | extern "C" { 31 | #include "libavcodec/avcodec.h" 32 | } 33 | #endif 34 | 35 | class CDemuxStream; 36 | 37 | class COMXStreamInfo 38 | { 39 | public: 40 | COMXStreamInfo(); 41 | 42 | ~COMXStreamInfo(); 43 | 44 | void Clear(); // clears current information 45 | 46 | enum AVCodecID codec; 47 | bool software; //force software decoding 48 | 49 | 50 | // VIDEO 51 | int fpsscale; // scale of 1000 and a rate of 29970 will result in 29.97 fps 52 | int fpsrate; 53 | int height; // height of the stream reported by the demuxer 54 | int width; // width of the stream reported by the demuxer 55 | float aspect; // display aspect as reported by demuxer 56 | bool vfr; // variable framerate 57 | bool stills; // there may be odd still frames in video 58 | int level; // encoder level of the stream reported by the decoder. used to qualify hw decoders. 59 | int profile; // encoder profile of the stream reported by the decoder. used to qualify hw decoders. 60 | bool ptsinvalid; // pts cannot be trusted (avi's). 61 | int orientation; // video orientation in clockwise degrees 62 | 63 | // AUDIO 64 | int channels; 65 | int samplerate; 66 | int bitrate; 67 | int blockalign; 68 | int bitspersample; 69 | 70 | // SUBTITLE 71 | int identifier; 72 | 73 | // CODEC EXTRADATA 74 | void* extradata; // extra data for codec to use 75 | unsigned int extrasize; // size of extra data 76 | unsigned int codec_tag; // extra identifier hints for decoding 77 | 78 | /* ac3/dts indof */ 79 | unsigned int framesize; 80 | uint32_t syncword; 81 | }; 82 | -------------------------------------------------------------------------------- /OMXOverlayCodec.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * Copyright (C) 2005-2008 Team XBMC 5 | * http://www.xbmc.org 6 | * 7 | * This Program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2, or (at your option) 10 | * any later version. 11 | * 12 | * This Program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with XBMC; see the file COPYING. If not, write to 19 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * http://www.gnu.org/copyleft/gpl.html 21 | * 22 | */ 23 | 24 | #include "OMXOverlay.h" 25 | #include "PlatformDefs.h" 26 | 27 | #include 28 | 29 | // VC_ messages, messages can be combined 30 | #define OC_ERROR 0x00000001 // an error occured, no other messages will be returned 31 | #define OC_BUFFER 0x00000002 // the decoder needs more data 32 | #define OC_OVERLAY 0x00000004 // the decoder decoded an overlay, call Decode(NULL, 0) again to parse the rest of the data 33 | 34 | class COMXStreamInfo; 35 | 36 | class COMXOverlayCodec 37 | { 38 | public: 39 | 40 | COMXOverlayCodec(const char* name) 41 | { 42 | m_codecName = name; 43 | } 44 | 45 | virtual ~COMXOverlayCodec() {} 46 | 47 | /* 48 | * Open the decoder, returns true on success 49 | */ 50 | virtual bool Open(COMXStreamInfo &hints) = 0; 51 | 52 | /* 53 | * Dispose, Free all resources 54 | */ 55 | virtual void Dispose() = 0; 56 | 57 | /* 58 | * returns one or a combination of VC_ messages 59 | * pData and iSize can be NULL, this means we should flush the rest of the data. 60 | */ 61 | virtual int Decode(BYTE* data, int size, double pts, double duration) = 0; 62 | 63 | /* 64 | * Reset the decoder. 65 | * Should be the same as calling Dispose and Open after each other 66 | */ 67 | virtual void Reset() = 0; 68 | 69 | /* 70 | * Flush the current working packet 71 | * This may leave the internal state intact 72 | */ 73 | virtual void Flush() = 0; 74 | 75 | /* 76 | * returns a valid overlay or NULL 77 | * the data is valid until the next Decode call 78 | */ 79 | virtual COMXOverlay* GetOverlay() = 0; 80 | 81 | /* 82 | * return codecs name 83 | */ 84 | virtual const char* GetName() { return m_codecName.c_str(); } 85 | 86 | private: 87 | std::string m_codecName; 88 | }; 89 | -------------------------------------------------------------------------------- /Unicode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Copyright Digital Mars 2003 - 2009. 4 | // Authors: Walter Bright, Sean Kelly 5 | 6 | // Boost Software License - Version 1.0 - August 17th, 2003 7 | 8 | // Permission is hereby granted, free of charge, to any person or organization 9 | // obtaining a copy of the software and accompanying documentation covered by 10 | // this license (the "Software") to use, reproduce, display, distribute, 11 | // execute, and transmit the Software, and to prepare derivative works of the 12 | // Software, and to permit third-parties to whom the Software is furnished to 13 | // do so, all subject to the following: 14 | 15 | // The copyright notices in the Software and this entire statement, including 16 | // the above license grant, this restriction and the following disclaimer, 17 | // must be included in all copies of the Software, in whole or in part, and 18 | // all derivative works of the Software, unless such copies or derivative 19 | // works are solely in the form of machine-executable object code generated by 20 | // a source language processor. 21 | 22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 25 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 26 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 27 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 | // DEALINGS IN THE SOFTWARE. 29 | 30 | #include 31 | #include 32 | 33 | /******************************* 34 | * Test if c is a valid UTF-32 character. 35 | * 36 | * \uFFFE and \uFFFF are considered valid by this function, 37 | * as they are permitted for internal use by an application, 38 | * but they are not allowed for interchange by the Unicode standard. 39 | * 40 | * Returns: true if it is, false if not. 41 | */ 42 | 43 | inline bool isValidChar32(char32_t c) BOOST_NOEXCEPT 44 | { 45 | /* Note: FFFE and FFFF are specifically permitted by the 46 | * Unicode standard for application internal use, but are not 47 | * allowed for interchange. 48 | * (thanks to Arcane Jill) 49 | */ 50 | 51 | return c < 0xD800 || 52 | (c > 0xDFFF && c <= 0x10FFFF /*&& c != 0xFFFE && c != 0xFFFF*/); 53 | } 54 | 55 | /*************** 56 | * Decodes and returns character starting at s[idx]. idx is advanced past the 57 | * decoded character. If the character is not well formed, an exception is 58 | * thrown and idx remains unchanged. 59 | */ 60 | 61 | char32_t decodeUtf8(const char* s, size_t len, size_t& idx); 62 | -------------------------------------------------------------------------------- /prepare-native-raspbian.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Patching makefiles..." 4 | echo "FLOAT=hard 5 | 6 | CFLAGS += -mfloat-abi=hard -mcpu=arm1176jzf-s -fomit-frame-pointer -mabi=aapcs-linux -mtune=arm1176jzf-s -mfpu=vfp -Wno-psabi -mno-apcs-stack-check -O3 -mstructure-size-boundary=32 -mno-sched-prolog -march=armv6zk `pkg-config dbus-1 --cflags` 7 | 8 | BUILDROOT :=/usr/local/src/omxplayer 9 | TOOLCHAIN :=/usr/ 10 | LD := \$(TOOLCHAIN)/bin/ld 11 | CC := \$(TOOLCHAIN)/bin/gcc-4.7 12 | CXX := \$(TOOLCHAIN)/bin/g++-4.7 13 | OBJDUMP := \$(TOOLCHAIN)/bin/objdump 14 | RANLIB := \$(TOOLCHAIN)/bin/ranlib 15 | STRIP := \$(TOOLCHAIN)/bin/strip 16 | AR := \$(TOOLCHAIN)/bin/ar 17 | CXXCP := \$(CXX) -E 18 | 19 | LDFLAGS += -L/opt/vc/lib -L/lib -L/usr/lib -lfreetype 20 | INCLUDES += -I/opt/vc/include/interface/vcos/pthreads \ 21 | -I/opt/vc/include \ 22 | -I/opt/vc/include/interface/vmcs_host \ 23 | -I/opt/vc/include/interface/vmcs_host/linux \ 24 | -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include \ 25 | -I/usr/include \ 26 | -I/usr/include/freetype2" > Makefile.include 27 | 28 | sed -i '/--enable-cross-compile \\/d;' Makefile.ffmpeg 29 | sed -i 's/ --cross-prefix=$(HOST)-//g;' Makefile.ffmpeg 30 | sed -i 's/ --disable-debug \\/ --disable-debug /g;' Makefile.ffmpeg 31 | 32 | sed -i 's/$(HOST)-//g;' Makefile.* 33 | sed -i 's/ -j9//g;' Makefile.* 34 | sed -i 's/#arm-unknown-linux-gnueabi-strip/arm-unknown-linux-gnueabi-strip/g;' Makefile 35 | sed -i 's/arm-unknown-linux-gnueabi-strip/strip/g;' Makefile 36 | 37 | echo " 38 | install: dist 39 | cp omxplayer-dist/* / -r 40 | 41 | uninstall: 42 | rm -rf /usr/bin/omxplayer 43 | rm -rf /usr/bin/omxplayer.bin 44 | rm -rf /usr/lib/omxplayer 45 | rm -rf /usr/share/doc/omxplayer 46 | " >> Makefile 47 | 48 | echo "Installing packages..." 49 | sudo apt-get update 50 | sudo apt-get -y install ca-certificates git-core subversion binutils libva1 libpcre3-dev libidn11-dev libboost1.50-dev libfreetype6-dev libusb-1.0-0-dev libdbus-1-dev libssl-dev 51 | sudo apt-get -y install gcc-4.7 g++-4.7 52 | 53 | 54 | echo "Installing the rpi-update script..." 55 | sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update 56 | echo "Updating firmware..." 57 | sudo rpi-update 58 | 59 | echo "In order to compile ffmpeg you need to set memory_split to 16 for 256MB RAM PIs (0 does not work) or to at most 256 for 512MB RAM PIs, respectively. Otherwise there is not enough RAM to compile ffmpeg. Please do the apropriate in the raspi-config and select finish to reboot your RPi. Warning: to run compiled omxplayer please start raspi-config again and set memory_split to at least 128. [Press RETURN to continue]" 60 | read -r REPLY 61 | sudo raspi-config 62 | 63 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include Makefile.include 2 | 3 | CFLAGS+=-std=c++0x -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -DTARGET_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CMAKE_CONFIG -D__VIDEOCORE4__ -U_FORTIFY_SOURCE -Wall -DHAVE_OMXLIB -DUSE_EXTERNAL_FFMPEG -DHAVE_LIBAVCODEC_AVCODEC_H -DHAVE_LIBAVUTIL_OPT_H -DHAVE_LIBAVUTIL_MEM_H -DHAVE_LIBAVUTIL_AVUTIL_H -DHAVE_LIBAVFORMAT_AVFORMAT_H -DHAVE_LIBAVFILTER_AVFILTER_H -DHAVE_LIBSWRESAMPLE_SWRESAMPLE_H -DOMX -DOMX_SKIP64BIT -ftree-vectorize -DUSE_EXTERNAL_OMX -DTARGET_RASPBERRY_PI -DUSE_EXTERNAL_LIBBCM_HOST 4 | 5 | LDFLAGS+=-L./ -Lffmpeg_compiled/usr/local/lib/ -lc -lWFC -lGLESv2 -lEGL -lbcm_host -lopenmaxil -lfreetype -lz 6 | 7 | #INCLUDES+=-I./ -Ilinux -Iffmpeg_compiled/usr/local/include/ -I /usr/include/dbus-1.0 -I /usr/lib/arm-linux-gnueabihf/dbus-1.0/include 8 | INCLUDES+=-I./ -Ilinux -Iffmpeg_compiled/usr/local/include/ 9 | 10 | DIST ?= omxplayer-dist 11 | 12 | SRC=linux/XMemUtils.cpp \ 13 | utils/log.cpp \ 14 | DynamicDll.cpp \ 15 | utils/PCMRemap.cpp \ 16 | utils/RegExp.cpp \ 17 | OMXSubtitleTagSami.cpp \ 18 | OMXOverlayCodecText.cpp \ 19 | BitstreamConverter.cpp \ 20 | linux/RBP.cpp \ 21 | OMXThread.cpp \ 22 | OMXReader.cpp \ 23 | OMXStreamInfo.cpp \ 24 | OMXAudioCodecOMX.cpp \ 25 | OMXCore.cpp \ 26 | OMXVideo.cpp \ 27 | OMXAudio.cpp \ 28 | OMXClock.cpp \ 29 | File.cpp \ 30 | OMXPlayerVideo.cpp \ 31 | OMXPlayerAudio.cpp \ 32 | OMXPlayerSubtitles.cpp \ 33 | OMXPlayerSync.cpp \ 34 | SubtitleRenderer.cpp \ 35 | Unicode.cpp \ 36 | Srt.cpp \ 37 | KeyConfig.cpp \ 38 | OMXControl.cpp \ 39 | Keyboard.cpp \ 40 | omxplayer.cpp \ 41 | 42 | OBJS+=$(filter %.o,$(SRC:.cpp=.o)) 43 | 44 | all: omxplayer.bin 45 | 46 | %.o: %.cpp 47 | @rm -f $@ 48 | $(CXX) $(CFLAGS) $(INCLUDES) -c $< -o $@ -Wno-deprecated-declarations 49 | 50 | version: 51 | bash gen_version.sh > version.h 52 | 53 | omxplayer.bin: version $(OBJS) 54 | $(CXX) $(LDFLAGS) -o omxplayer.bin $(OBJS) -lvchiq_arm -lvcos -ldbus-1 -lrt -lpthread -lavutil -lavcodec -lavformat -lswscale -lswresample -lpcre 55 | $(STRIP) omxplayer.bin 56 | 57 | clean: 58 | for i in $(OBJS); do (if test -e "$$i"; then ( rm $$i ); fi ); done 59 | @rm -f omxplayer.old.log omxplayer.log 60 | @rm -f omxplayer.bin 61 | @rm -rf $(DIST) 62 | @rm -f omxplayer-dist.tar.gz 63 | 64 | ffmpeg: 65 | @rm -rf ffmpeg 66 | make -f Makefile.ffmpeg 67 | make -f Makefile.ffmpeg install 68 | 69 | dist: omxplayer.bin 70 | mkdir -p $(DIST)/usr/lib/omxplayer 71 | mkdir -p $(DIST)/usr/bin 72 | mkdir -p $(DIST)/usr/share/doc/omxplayer 73 | cp omxplayer omxplayer.bin $(DIST)/usr/bin 74 | cp COPYING $(DIST)/usr/share/doc/omxplayer 75 | cp README.md $(DIST)/usr/share/doc/omxplayer/README 76 | cp -a ffmpeg_compiled/usr/local/lib/*.so* $(DIST)/usr/lib/omxplayer/ 77 | cd $(DIST); tar -czf ../$(DIST).tgz * 78 | -------------------------------------------------------------------------------- /utils/RegExp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | * Copyright (C) 2005-2008 Team XBMC 4 | * http://www.xbmc.org 5 | * 6 | * This Program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2, or (at your option) 9 | * any later version. 10 | * 11 | * This Program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with XBMC; see the file COPYING. If not, write to 18 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 19 | * http://www.gnu.org/copyleft/gpl.html 20 | * 21 | */ 22 | 23 | #ifndef REGEXP_H 24 | #define REGEXP_H 25 | 26 | #include 27 | #include 28 | 29 | namespace PCRE { 30 | #ifdef _WIN32 31 | #define PCRE_STATIC 32 | #include "lib/win32/pcre/pcre.h" 33 | #else 34 | #include 35 | #endif 36 | } 37 | 38 | // maximum of 20 backreferences 39 | // OVEVCOUNT must be a multiple of 3 40 | const int OVECCOUNT=(20+1)*3; 41 | 42 | class CRegExp 43 | { 44 | public: 45 | CRegExp(bool caseless = false); 46 | CRegExp(const CRegExp& re); 47 | ~CRegExp(); 48 | 49 | CRegExp* RegComp(const char *re); 50 | CRegExp* RegComp(const std::string& re) { return RegComp(re.c_str()); } 51 | int RegFind(const char *str, int startoffset = 0); 52 | int RegFind(const std::string& str, int startoffset = 0) { return RegFind(str.c_str(), startoffset); } 53 | char* GetReplaceString( const char* sReplaceExp ); 54 | int GetFindLen() 55 | { 56 | if (!m_re || !m_bMatched) 57 | return 0; 58 | 59 | return (m_iOvector[1] - m_iOvector[0]); 60 | }; 61 | int GetSubCount() { return m_iMatchCount - 1; } // PCRE returns the number of sub-patterns + 1 62 | int GetSubStart(int iSub) { return m_iOvector[iSub*2]; } // normalized to match old engine 63 | int GetSubLength(int iSub) { return (m_iOvector[(iSub*2)+1] - m_iOvector[(iSub*2)]); } // correct spelling 64 | int GetCaptureTotal(); 65 | std::string GetMatch(int iSub = 0); 66 | const std::string& GetPattern() { return m_pattern; } 67 | bool GetNamedSubPattern(const char* strName, std::string& strMatch); 68 | void DumpOvector(int iLog); 69 | const CRegExp& operator= (const CRegExp& re); 70 | 71 | private: 72 | void Cleanup() { if (m_re) { PCRE::pcre_free(m_re); m_re = NULL; } } 73 | 74 | private: 75 | PCRE::pcre* m_re; 76 | int m_iOvector[OVECCOUNT]; 77 | int m_iMatchCount; 78 | int m_iOptions; 79 | bool m_bMatched; 80 | std::string m_subject; 81 | std::string m_pattern; 82 | }; 83 | 84 | typedef std::vector VECCREGEXP; 85 | 86 | #endif 87 | 88 | -------------------------------------------------------------------------------- /utils/Enforce.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Author: Torarin Hals Bakke (2012) 4 | 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | class Enforce_error : public std::exception { 36 | std::string what_; 37 | std::string user_friendly_what_; 38 | public: 39 | template 40 | explicit Enforce_error(T&& what_arg, U&& user_friendly_what_arg) 41 | : what_(std::forward(what_arg)), 42 | user_friendly_what_(std::forward(user_friendly_what_arg)) 43 | {} 44 | 45 | #if __GNUC__ == 4 && __GNUC_MINOR__ == 6 46 | ~Enforce_error() throw() {} 47 | #endif 48 | 49 | const char* what() const BOOST_NOEXCEPT { 50 | return what_.c_str(); 51 | } 52 | 53 | const std::string& user_friendly_what() const BOOST_NOEXCEPT { 54 | return user_friendly_what_; 55 | } 56 | }; 57 | 58 | template 59 | void enforce(bool condition, T&& msg, U&& user_friendly_msg) { 60 | static_assert(std::is_convertible::value, 61 | "msg must be convertible to std::string"); 62 | static_assert(std::is_convertible::value, 63 | "user_friendly_msg must be convertible to std::string"); 64 | if (!condition) 65 | throw Enforce_error(std::forward(msg), std::forward(user_friendly_msg)); 66 | } 67 | 68 | #define ENFORCE_MESSAGE "Enforcement failed in " __FILE__ "(" BOOST_STRINGIZE(__LINE__) ")" 69 | 70 | #define ENFORCE(condition) enforce(condition, ENFORCE_MESSAGE, "") 71 | #define ENFORCE2(condition, user_friendly_msg) enforce(condition, ENFORCE_MESSAGE, user_friendly_msg) 72 | -------------------------------------------------------------------------------- /Srt.cpp: -------------------------------------------------------------------------------- 1 | // Author: Torarin Hals Bakke (2012) 2 | 3 | // Boost Software License - Version 1.0 - August 17th, 2003 4 | 5 | // Permission is hereby granted, free of charge, to any person or organization 6 | // obtaining a copy of the software and accompanying documentation covered by 7 | // this license (the "Software") to use, reproduce, display, distribute, 8 | // execute, and transmit the Software, and to prepare derivative works of the 9 | // Software, and to permit third-parties to whom the Software is furnished to 10 | // do so, all subject to the following: 11 | 12 | // The copyright notices in the Software and this entire statement, including 13 | // the above license grant, this restriction and the following disclaimer, 14 | // must be included in all copies of the Software, in whole or in part, and 15 | // all derivative works of the Software, unless such copies or derivative 16 | // works are solely in the form of machine-executable object code generated by 17 | // a source language processor. 18 | 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | // DEALINGS IN THE SOFTWARE. 26 | 27 | #include "Srt.h" 28 | 29 | #include 30 | #include 31 | 32 | namespace { 33 | unsigned int timecode_to_milliseconds(unsigned int h, 34 | unsigned int m, 35 | unsigned int s, 36 | unsigned int f) 37 | { 38 | return h*3600000 + 39 | m*60000 + 40 | s*1000 + 41 | f; 42 | } 43 | } 44 | 45 | template 46 | T& getline(T&& input, U&& str) { 47 | std::getline(std::forward(input), std::forward(str)); 48 | if (!str.empty() && str.back() == '\r') { 49 | str.resize(str.size()-1); 50 | } 51 | return input; 52 | } 53 | 54 | bool ReadSrt(const std::string& filename, std::vector& subtitles) { 55 | std::ifstream srt(filename); 56 | if (!srt) return false; 57 | 58 | for (std::string line; getline(srt, line);) { 59 | unsigned int h, m, s, f, h2, m2, s2, f2; 60 | 61 | if (sscanf(line.c_str(), "%u:%u:%u,%u --> %u:%u:%u,%u", 62 | &h, &m, &s, &f, &h2, &m2, &s2, &f2) 63 | != 8) 64 | { 65 | continue; 66 | } 67 | 68 | auto start = (int) timecode_to_milliseconds(h, m, s, f); 69 | auto stop = (int) timecode_to_milliseconds(h2, m2, s2 ,f2); 70 | 71 | std::vector text_lines; 72 | while (getline(srt, line)) { 73 | if (line.empty()) break; 74 | text_lines.push_back(std::move(line)); 75 | } 76 | 77 | if (!subtitles.empty() && subtitles.back().stop > stop) 78 | continue; 79 | 80 | subtitles.emplace_back(start, stop, std::move(text_lines)); 81 | } 82 | 83 | return true; 84 | } 85 | -------------------------------------------------------------------------------- /File.h: -------------------------------------------------------------------------------- 1 | /* 2 | * XBMC Media Center 3 | * Copyright (c) 2002 Frodo 4 | * Portions Copyright (c) by the authors of ffmpeg and xvid 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | */ 20 | 21 | // File.h: interface for the CFile class. 22 | // 23 | ////////////////////////////////////////////////////////////////////// 24 | 25 | #if !defined(AFX_FILE_H__A7ED6320_C362_49CB_8925_6C6C8CAE7B78__INCLUDED_) 26 | #define AFX_FILE_H__A7ED6320_C362_49CB_8925_6C6C8CAE7B78__INCLUDED_ 27 | 28 | #if _MSC_VER > 1000 29 | #pragma once 30 | #endif // _MSC_VER > 1000 31 | 32 | #define FFMPEG_FILE_BUFFER_SIZE 32768 33 | 34 | namespace XFILE 35 | { 36 | 37 | /* indicate that caller can handle truncated reads, where function returns before entire buffer has been filled */ 38 | #define READ_TRUNCATED 0x01 39 | 40 | /* indicate that that caller support read in the minimum defined chunk size, this disables internal cache then */ 41 | #define READ_CHUNKED 0x02 42 | 43 | /* use cache to access this file */ 44 | #define READ_CACHED 0x04 45 | 46 | /* open without caching. regardless to file type. */ 47 | #define READ_NO_CACHE 0x08 48 | 49 | /* calcuate bitrate for file while reading */ 50 | #define READ_BITRATE 0x10 51 | 52 | typedef enum { 53 | IOCTRL_NATIVE = 1, /**< SNativeIoControl structure, containing what should be passed to native ioctrl */ 54 | IOCTRL_SEEK_POSSIBLE = 2, /**< return 0 if known not to work, 1 if it should work */ 55 | IOCTRL_CACHE_STATUS = 3, /**< SCacheStatus structure */ 56 | IOCTRL_CACHE_SETRATE = 4, /**< unsigned int with with speed limit for caching in bytes per second */ 57 | } EIoControl; 58 | 59 | class CFile 60 | { 61 | public: 62 | CFile(); 63 | ~CFile(); 64 | 65 | bool Open(const CStdString& strFileName, unsigned int flags = 0); 66 | bool OpenForWrite(const CStdString& strFileName, bool bOverWrite); 67 | unsigned int Read(void* lpBuf, int64_t uiBufSize); 68 | int Write(const void* lpBuf, int64_t uiBufSize); 69 | int64_t Seek(int64_t iFilePosition, int iWhence = SEEK_SET); 70 | int64_t GetPosition(); 71 | int64_t GetLength(); 72 | void Close(); 73 | static bool Exists(const CStdString& strFileName, bool bUseCache = true); 74 | int GetChunkSize() { return 6144 /*FFMPEG_FILE_BUFFER_SIZE*/; }; 75 | int IoControl(EIoControl request, void* param); 76 | bool IsEOF(); 77 | private: 78 | unsigned int m_flags; 79 | FILE *m_pFile; 80 | int64_t m_iLength; 81 | bool m_bPipe; 82 | }; 83 | 84 | }; 85 | #endif // !defined(AFX_FILE_H__A7ED6320_C362_49CB_8925_6C6C8CAE7B78__INCLUDED_) 86 | -------------------------------------------------------------------------------- /linux/XMemUtils.d: -------------------------------------------------------------------------------- 1 | linux/XMemUtils.o: linux/XMemUtils.cpp \ 2 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/stdlib.h \ 3 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/features.h \ 4 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/sys/cdefs.h \ 5 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/wordsize.h \ 6 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/gnu/stubs.h \ 7 | /usr/local/bcm-gcc/bin/../lib/gcc/arm-bcm2708-linux-gnueabi/4.5.1/include/stddef.h \ 8 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/waitflags.h \ 9 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/waitstatus.h \ 10 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/endian.h \ 11 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/endian.h \ 12 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/byteswap.h \ 13 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/xlocale.h \ 14 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/sys/types.h \ 15 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/types.h \ 16 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/typesizes.h \ 17 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/time.h \ 18 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/sys/select.h \ 19 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/select.h \ 20 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/sigset.h \ 21 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/time.h \ 22 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/sys/sysmacros.h \ 23 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/pthreadtypes.h \ 24 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/alloca.h \ 25 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/stdio.h \ 26 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/libio.h \ 27 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/_G_config.h \ 28 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/wchar.h \ 29 | /usr/local/bcm-gcc/bin/../lib/gcc/arm-bcm2708-linux-gnueabi/4.5.1/include/stdarg.h \ 30 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/stdio_lim.h \ 31 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/sys_errlist.h \ 32 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/unistd.h \ 33 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/posix_opt.h \ 34 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/environments.h \ 35 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/bits/confname.h \ 36 | /usr/local/bcm-gcc/bin/../arm-bcm2708-linux-gnueabi//sys-root/usr/include/getopt.h \ 37 | linux/XMemUtils.h 38 | -------------------------------------------------------------------------------- /dbuscontrol.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | OMXPLAYER_DBUS_ADDR="/tmp/omxplayerdbus" 6 | OMXPLAYER_DBUS_PID="/tmp/omxplayerdbus.pid" 7 | export DBUS_SESSION_BUS_ADDRESS=`cat $OMXPLAYER_DBUS_ADDR` 8 | export DBUS_SESSION_BUS_PID=`cat $OMXPLAYER_DBUS_PID` 9 | 10 | [ -z "$DBUS_SESSION_BUS_ADDRESS" ] && { echo "Must have DBUS_SESSION_BUS_ADDRESS" >&2; exit 1; } 11 | 12 | case $1 in 13 | status) 14 | duration=`dbus-send --print-reply=literal --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Duration` 15 | [ $? -ne 0 ] && exit 1 16 | duration="$(awk '{print $2}' <<< "$duration")" 17 | 18 | position=`dbus-send --print-reply=literal --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Position` 19 | [ $? -ne 0 ] && exit 1 20 | position="$(awk '{print $2}' <<< "$position")" 21 | 22 | playstatus=`dbus-send --print-reply=literal --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.PlaybackStatus` 23 | [ $? -ne 0 ] && exit 1 24 | playstatus="$(sed 's/^ *//;s/ *$//;' <<< "$playstatus")" 25 | 26 | paused="true" 27 | [ "$playstatus" == "Playing" ] && paused="false" 28 | echo "Duration: $duration" 29 | echo "Position: $position" 30 | echo "Paused: $paused" 31 | ;; 32 | 33 | pause) 34 | dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:16 >/dev/null 35 | ;; 36 | 37 | stop) 38 | dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:15 >/dev/null 39 | ;; 40 | 41 | seek) 42 | dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Seek int64:$2 >/dev/null 43 | ;; 44 | 45 | setposition) 46 | dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.SetPosition objpath:/not/used int64:$2 >/dev/null 47 | ;; 48 | 49 | setvideopos) 50 | dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.VideoPos objpath:/not/used string:"$2 $3 $4 $5" >/dev/null 51 | ;; 52 | 53 | hidevideo) 54 | dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:28 >/dev/null 55 | ;; 56 | 57 | unhidevideo) 58 | dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:29 >/dev/null 59 | ;; 60 | 61 | volumeup) 62 | dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:18 >/dev/null 63 | ;; 64 | 65 | volumedown) 66 | dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:17 >/dev/null 67 | ;; 68 | 69 | *) 70 | echo "usage: $0 status|pause|stop|seek|volumeup|volumedown|setposition [position in microseconds]|hidevideo|unhidevideo|setvideopos [x1 y1 x2 y2]" >&2 71 | exit 1 72 | ;; 73 | esac 74 | -------------------------------------------------------------------------------- /OMXOverlayText.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * Copyright (C) 2005-2008 Team XBMC 5 | * http://www.xbmc.org 6 | * 7 | * This Program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2, or (at your option) 10 | * any later version. 11 | * 12 | * This Program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with XBMC; see the file COPYING. If not, write to 19 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * http://www.gnu.org/copyleft/gpl.html 21 | * 22 | */ 23 | 24 | #include "OMXOverlay.h" 25 | #include 26 | 27 | class COMXOverlayText : public COMXOverlay 28 | { 29 | public: 30 | 31 | enum ElementType 32 | { 33 | ELEMENT_TYPE_NONE = -1, 34 | ELEMENT_TYPE_TEXT = 1, 35 | ELEMENT_TYPE_PROPERTY = 2 36 | }; 37 | 38 | class CElement 39 | { 40 | public: 41 | CElement(ElementType type) 42 | { 43 | m_type = type; 44 | } 45 | 46 | virtual ~CElement() 47 | { 48 | } 49 | 50 | bool IsElementType(ElementType type) { return (type == m_type); } 51 | 52 | CElement* pNext; 53 | ElementType m_type; 54 | }; 55 | 56 | class CElementText : public CElement 57 | { 58 | public: 59 | CElementText(const char* strText, int size = -1) : CElement(ELEMENT_TYPE_TEXT) 60 | { 61 | if(size == -1) 62 | m_text = strdup(strText); 63 | else 64 | { 65 | m_text = (char*)malloc(size+1); 66 | memcpy(m_text, strText, size); 67 | m_text[size] = '\0'; 68 | } 69 | } 70 | 71 | virtual ~CElementText() 72 | { 73 | if (m_text) free(m_text); 74 | } 75 | 76 | char* m_text; 77 | }; 78 | 79 | class CElementProperty : public CElement 80 | { 81 | CElementProperty() : CElement(ELEMENT_TYPE_PROPERTY) 82 | { 83 | bItalic = false; 84 | bBold = false; 85 | } 86 | 87 | public: 88 | bool bItalic; 89 | bool bBold; 90 | // color 91 | }; 92 | 93 | COMXOverlayText() : COMXOverlay(OMXOVERLAY_TYPE_TEXT) 94 | { 95 | m_pHead = NULL; 96 | m_pEnd = NULL; 97 | } 98 | 99 | virtual ~COMXOverlayText() 100 | { 101 | CElement* pTemp; 102 | while (m_pHead) 103 | { 104 | pTemp = m_pHead; 105 | m_pHead = m_pHead->pNext; 106 | delete pTemp; 107 | } 108 | } 109 | 110 | void AddElement(COMXOverlayText::CElement* pElement) 111 | { 112 | pElement->pNext = NULL; 113 | 114 | if (!m_pHead) 115 | { // first element - set our head to this element, and update the end to the new element 116 | m_pHead = pElement; 117 | m_pEnd = pElement; 118 | } 119 | else 120 | { // extra element - add to the end and update the end to the new element 121 | m_pEnd->pNext = pElement; 122 | m_pEnd = pElement; 123 | } 124 | } 125 | 126 | CElement* m_pHead; 127 | CElement* m_pEnd; 128 | }; 129 | 130 | -------------------------------------------------------------------------------- /utils/Mailbox.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Author: Torarin Hals Bakke (2012) 4 | 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "variant.hpp" 36 | #include "LockBlock.h" 37 | #include "FunctorVisitor.h" 38 | 39 | template 40 | class Mailbox { 41 | public: 42 | template 43 | void send(T&& msg) { 44 | LOCK_BLOCK (messages_lock_) { 45 | messages_.push_back(std::forward(msg)); 46 | messages_cond_.notify_one(); 47 | } 48 | } 49 | 50 | template 51 | void receive(Funs&&... funs) { 52 | for (;;) { 53 | LOCK_BLOCK (messages_lock_) 54 | if (messages_.empty()) break; 55 | 56 | auto extract_message = [&]() { 57 | LOCK_BLOCK (messages_lock_) { 58 | utils::variant msg(std::move(messages_.front())); 59 | messages_.pop_front(); 60 | return msg; 61 | } 62 | assert(0); 63 | }; 64 | 65 | utils::apply_visitor(functor_visitor(funs...), 66 | extract_message()); 67 | } 68 | } 69 | 70 | template 71 | void receive_wait(const std::chrono::duration& rel_time, 72 | Funs&&... funs) 73 | { 74 | { 75 | std::unique_lock lock(messages_lock_); 76 | if (!messages_cond_.wait_for(lock, 77 | rel_time, 78 | [&]{return !messages_.empty();})) 79 | return; 80 | } 81 | receive(std::forward(funs)...); 82 | } 83 | 84 | void clear() { 85 | LOCK_BLOCK(messages_lock_) 86 | messages_.clear(); 87 | } 88 | 89 | 90 | private: 91 | std::deque> messages_; 92 | std::mutex messages_lock_; 93 | std::condition_variable messages_cond_; 94 | }; 95 | -------------------------------------------------------------------------------- /utils/ScopeExit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Author: Torarin Hals Bakke (2012) 4 | 5 | // Implementation of the scope guard idiom 6 | // (http://www.drdobbs.com/cpp/generic-change-the-way-you-write-excepti/184403758), 7 | // including a SCOPE_EXIT macro a la the D programming language. 8 | 9 | // Boost Software License - Version 1.0 - August 17th, 2003 10 | 11 | // Permission is hereby granted, free of charge, to any person or organization 12 | // obtaining a copy of the software and accompanying documentation covered by 13 | // this license (the "Software") to use, reproduce, display, distribute, 14 | // execute, and transmit the Software, and to prepare derivative works of the 15 | // Software, and to permit third-parties to whom the Software is furnished to 16 | // do so, all subject to the following: 17 | 18 | // The copyright notices in the Software and this entire statement, including 19 | // the above license grant, this restriction and the following disclaimer, 20 | // must be included in all copies of the Software, in whole or in part, and 21 | // all derivative works of the Software, unless such copies or derivative 22 | // works are solely in the form of machine-executable object code generated by 23 | // a source language processor. 24 | 25 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 28 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 29 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 30 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 31 | // DEALINGS IN THE SOFTWARE. 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "utils/log.h" 41 | 42 | template 43 | class Scope_guard { 44 | T fun_; 45 | 46 | public: 47 | Scope_guard& operator=(const Scope_guard&) = delete; 48 | 49 | // This copy constructor cannot be deleted due to the SCOPE_EXIT macro, 50 | // but the compiler should elide it 51 | Scope_guard(const Scope_guard&); 52 | 53 | explicit Scope_guard(const T& fun): fun_(fun) {} 54 | explicit Scope_guard(T&& fun): fun_(std::move(fun)) {} 55 | 56 | ~Scope_guard() BOOST_NOEXCEPT { 57 | try { 58 | fun_(); 59 | } catch (std::exception& e) { 60 | CLog::Log(LOGSEVERE, "Scope_guard exit function threw %s (%s)", 61 | typeid(e).name(), e.what()); 62 | #ifndef NDEBUG 63 | printf("Scope_guard exit function threw %s (%s)\n", 64 | typeid(e).name(), e.what()); 65 | abort(); 66 | #endif 67 | } catch (...) { 68 | CLog::Log(LOGSEVERE, "Scope_guard exit function threw an object unrelated to std::exception"); 69 | #ifndef NDEBUG 70 | printf("Scope_guard exit function threw an object unrelated to std::exception\n"); 71 | abort(); 72 | #endif 73 | } 74 | } 75 | }; 76 | 77 | struct SCOPE_EXIT_tag {}; 78 | 79 | template 80 | Scope_guard::type> operator+(SCOPE_EXIT_tag, T&& fun) { 81 | return Scope_guard::type>(std::forward(fun)); 82 | } 83 | 84 | // Usage: 85 | // SCOPE_EXIT { 86 | // ... 87 | // }; 88 | 89 | #define SCOPE_EXIT \ 90 | auto BOOST_JOIN(scope_guard_, __LINE__) = SCOPE_EXIT_tag{} + [&] 91 | -------------------------------------------------------------------------------- /OMXThread.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2008 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #if (defined HAVE_CONFIG_H) && (!defined WIN32) 23 | #include "config.h" 24 | #elif defined(_WIN32) 25 | #include "system.h" 26 | #endif 27 | 28 | #include "OMXThread.h" 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include "utils/log.h" 35 | 36 | #ifdef CLASSNAME 37 | #undef CLASSNAME 38 | #endif 39 | #define CLASSNAME "OMXThread" 40 | 41 | OMXThread::OMXThread() 42 | { 43 | pthread_mutex_init(&m_lock, NULL); 44 | pthread_attr_setdetachstate(&m_tattr, PTHREAD_CREATE_JOINABLE); 45 | pthread_attr_init(&m_tattr); 46 | m_thread = 0; 47 | m_bStop = false; 48 | m_running = false; 49 | } 50 | 51 | OMXThread::~OMXThread() 52 | { 53 | pthread_mutex_destroy(&m_lock); 54 | pthread_attr_destroy(&m_tattr); 55 | } 56 | 57 | bool OMXThread::StopThread() 58 | { 59 | if(!m_running) 60 | { 61 | CLog::Log(LOGDEBUG, "%s::%s - No thread running\n", CLASSNAME, __func__); 62 | return false; 63 | } 64 | 65 | m_bStop = true; 66 | pthread_join(m_thread, NULL); 67 | m_running = false; 68 | 69 | m_thread = 0; 70 | 71 | CLog::Log(LOGDEBUG, "%s::%s - Thread stopped\n", CLASSNAME, __func__); 72 | return true; 73 | } 74 | 75 | bool OMXThread::Create() 76 | { 77 | if(m_running) 78 | { 79 | CLog::Log(LOGERROR, "%s::%s - Thread already running\n", CLASSNAME, __func__); 80 | return false; 81 | } 82 | 83 | m_bStop = false; 84 | m_running = true; 85 | 86 | pthread_create(&m_thread, &m_tattr, &OMXThread::Run, this); 87 | 88 | CLog::Log(LOGDEBUG, "%s::%s - Thread with id %d started\n", CLASSNAME, __func__, (int)m_thread); 89 | return true; 90 | } 91 | 92 | bool OMXThread::Running() 93 | { 94 | return m_running; 95 | } 96 | 97 | pthread_t OMXThread::ThreadHandle() 98 | { 99 | return m_thread; 100 | } 101 | 102 | void *OMXThread::Run(void *arg) 103 | { 104 | OMXThread *thread = static_cast(arg); 105 | thread->Process(); 106 | 107 | CLog::Log(LOGDEBUG, "%s::%s - Exited thread with id %d\n", CLASSNAME, __func__, (int)thread->ThreadHandle()); 108 | pthread_exit(NULL); 109 | } 110 | 111 | void OMXThread::Lock() 112 | { 113 | if(!m_running) 114 | { 115 | CLog::Log(LOGDEBUG, "%s::%s - No thread running\n", CLASSNAME, __func__); 116 | return; 117 | } 118 | 119 | pthread_mutex_lock(&m_lock); 120 | } 121 | 122 | void OMXThread::UnLock() 123 | { 124 | if(!m_running) 125 | { 126 | CLog::Log(LOGDEBUG, "%s::%s - No thread running\n", CLASSNAME, __func__); 127 | return; 128 | } 129 | 130 | pthread_mutex_unlock(&m_lock); 131 | } 132 | 133 | -------------------------------------------------------------------------------- /omxplayer: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # OMXPlayer launcher script. 4 | # 5 | 6 | OMXPLAYER_DIR=`dirname $0` 7 | OMXPLAYER_BIN="$OMXPLAYER_DIR/omxplayer.bin" 8 | OMXPLAYER_LIBS="/opt/vc/lib" 9 | 10 | if [ -e "$OMXPLAYER_DIR/ffmpeg_compiled" ]; then 11 | OMXPLAYER_LIBS="$OMXPLAYER_LIBS:$OMXPLAYER_DIR/ffmpeg_compiled" 12 | else 13 | OMXPLAYER_LIBS="$OMXPLAYER_LIBS:/usr/lib/omxplayer" 14 | fi 15 | 16 | refresh_regex='(|.* )(-r|--refresh)( .*|$)' 17 | audio_regex='.*\.(mp3|wav|wma|cda|ogg|ogm|aac|ac3|flac)( .*|$)' 18 | 19 | fbset_bin=`which fbset` 20 | xset_bin=`which xset` 21 | xrefresh_bin=`which xrefresh` 22 | 23 | if [ -z $NOREFRESH ] || [ "$NOREFRESH" == "0" ]; then 24 | if [[ $@ =~ $refresh_regex ]] && [[ ! $@ =~ $audio_regex ]]; then 25 | check_failed=0 26 | 27 | if [ -z $fbset_bin ]; then 28 | echo "WARNING: You are going to run omxplayer with -r/--refresh and you don't have fbset installed, this can cause black screen when it finishes playing." 29 | check_failed=1 30 | fi 31 | 32 | if [ ! -z $DISPLAY ]; then 33 | if [ -z $xset_bin ] || [ -z $xrefresh_bin ]; then 34 | echo "WARNING: You are going to run omxplayer with -r/--refresh and you don't have xset and xrefresh installed (x11-xserver-utils package on Debian/Raspbian), this can cause black screen when it finishes playing." 35 | check_failed=1 36 | fi 37 | fi 38 | 39 | if [ "$check_failed" == "1" ]; then 40 | read -sn 1 -p "Press any key to continue or Ctrl-C to quit." 41 | echo 42 | fi 43 | fi 44 | fi 45 | 46 | DBUS_CMD="dbus-daemon --fork --print-address 5 --print-pid 6 --session" 47 | OMXPLAYER_DBUS_ADDR="/tmp/omxplayerdbus" 48 | OMXPLAYER_DBUS_PID="/tmp/omxplayerdbus.pid" 49 | 50 | if [ ! -s "$OMXPLAYER_DBUS_PID" ] || ! pgrep -f "$DBUS_CMD" -F "$OMXPLAYER_DBUS_PID" >/dev/null; then 51 | #echo "starting dbus for the first time" >&2 52 | exec 5> "$OMXPLAYER_DBUS_ADDR" 53 | exec 6> "$OMXPLAYER_DBUS_PID" 54 | $DBUS_CMD 55 | until [ -s "$OMXPLAYER_DBUS_ADDR" ]; do 56 | echo "waiting for dbus address to appear" >&2 57 | sleep .2 58 | done 59 | fi 60 | 61 | DBUS_SESSION_BUS_ADDRESS=`cat $OMXPLAYER_DBUS_ADDR` 62 | DBUS_SESSION_BUS_PID=`cat $OMXPLAYER_DBUS_PID` 63 | 64 | export DBUS_SESSION_BUS_ADDRESS 65 | export DBUS_SESSION_BUS_PID 66 | 67 | LD_LIBRARY_PATH="$OMXPLAYER_LIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" $OMXPLAYER_BIN "$@"; true 68 | 69 | if [ ! -z $NOREFRESH ] && [ "$NOREFRESH" == "1" ]; then 70 | exit 0 71 | fi 72 | 73 | if [[ $@ =~ $audio_regex ]]; then 74 | exit 0 75 | fi 76 | 77 | if [[ $@ =~ $refresh_regex ]]; then 78 | if [ ! -z $fbset_bin ]; then 79 | DEPTH2=`$fbset_bin | head -3 | tail -1 | cut -d " " -f 10` 80 | 81 | if [ "$DEPTH2" == "8" ]; then 82 | DEPTH1=16 83 | elif [ "$DEPTH2" == "16" ] || [ "$DEPTH2" == "32" ]; then 84 | DEPTH1=8 85 | else 86 | DEPTH1=8 87 | DEPTH2=16 88 | fi 89 | 90 | $fbset_bin -depth $DEPTH1 > /dev/null 2>&1 91 | $fbset_bin -depth $DEPTH2 > /dev/null 2>&1 92 | fi 93 | 94 | if [ ! -z $xset_bin ] && [ ! -z $xrefresh_bin ]; then 95 | if [ -z $DISPLAY ]; then 96 | DISPLAY=":0" 97 | fi 98 | 99 | $xset_bin -display $DISPLAY -q > /dev/null 2>&1 100 | if [ "$?" == "0" ]; then 101 | $xrefresh_bin -display $DISPLAY > /dev/null 2>&1 102 | fi 103 | fi 104 | fi 105 | -------------------------------------------------------------------------------- /OMXClock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2008 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #ifndef _AVCLOCK_H_ 23 | #define _AVCLOCK_H_ 24 | 25 | #include "DllAvFormat.h" 26 | 27 | #include "OMXCore.h" 28 | 29 | #define DVD_TIME_BASE 1000000 30 | #define DVD_NOPTS_VALUE (-1LL<<52) // should be possible to represent in both double and __int64 31 | 32 | #define DVD_TIME_TO_SEC(x) ((int)((double)(x) / DVD_TIME_BASE)) 33 | #define DVD_TIME_TO_MSEC(x) ((int)((double)(x) * 1000 / DVD_TIME_BASE)) 34 | #define DVD_SEC_TO_TIME(x) ((double)(x) * DVD_TIME_BASE) 35 | #define DVD_MSEC_TO_TIME(x) ((double)(x) * DVD_TIME_BASE / 1000) 36 | 37 | #define DVD_PLAYSPEED_PAUSE 0 // frame stepping 38 | #define DVD_PLAYSPEED_NORMAL 1000 39 | 40 | #ifdef OMX_SKIP64BIT 41 | static inline OMX_TICKS ToOMXTime(int64_t pts) 42 | { 43 | OMX_TICKS ticks; 44 | ticks.nLowPart = pts; 45 | ticks.nHighPart = pts >> 32; 46 | return ticks; 47 | } 48 | static inline int64_t FromOMXTime(OMX_TICKS ticks) 49 | { 50 | int64_t pts = ticks.nLowPart | ((uint64_t)(ticks.nHighPart) << 32); 51 | return pts; 52 | } 53 | #else 54 | #define FromOMXTime(x) (x) 55 | #define ToOMXTime(x) (x) 56 | #endif 57 | 58 | class OMXClock 59 | { 60 | protected: 61 | bool m_pause; 62 | pthread_mutex_t m_lock; 63 | int m_omx_speed; 64 | OMX_U32 m_WaitMask; 65 | OMX_TIME_CLOCKSTATE m_eState; 66 | OMX_TIME_REFCLOCKTYPE m_eClock; 67 | private: 68 | COMXCoreComponent m_omx_clock; 69 | double m_last_media_time; 70 | double m_last_media_time_read; 71 | DllAvFormat m_dllAvFormat; 72 | 73 | public: 74 | OMXClock(); 75 | ~OMXClock(); 76 | void Lock(); 77 | void UnLock(); 78 | void OMXSetClockPorts(OMX_TIME_CONFIG_CLOCKSTATETYPE *clock, bool has_video, bool has_audio); 79 | bool OMXSetReferenceClock(bool has_audio, bool lock = true); 80 | bool OMXInitialize(); 81 | void OMXDeinitialize(); 82 | bool OMXIsPaused() { return m_pause; }; 83 | bool OMXStop(bool lock = true); 84 | bool OMXStep(int steps = 1, bool lock = true); 85 | bool OMXReset(bool has_video, bool has_audio, bool lock = true); 86 | double OMXMediaTime(bool lock = true); 87 | double OMXClockAdjustment(bool lock = true); 88 | bool OMXMediaTime(double pts, bool lock = true); 89 | bool OMXPause(bool lock = true); 90 | bool OMXResume(bool lock = true); 91 | bool OMXSetSpeed(int speed, bool lock = true, bool pause_resume = false); 92 | int OMXPlaySpeed() { return m_omx_speed; }; 93 | COMXCoreComponent *GetOMXClock(); 94 | bool OMXStateExecute(bool lock = true); 95 | void OMXStateIdle(bool lock = true); 96 | bool HDMIClockSync(bool lock = true); 97 | int64_t GetAbsoluteClock(); 98 | double GetClock(bool interpolated = true); 99 | static void OMXSleep(unsigned int dwMilliSeconds); 100 | }; 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /OMXPlayerSync.h: -------------------------------------------------------------------------------- 1 | #ifndef OMXPLAYERSYNCH_H 2 | #define OMXPLAYERSYNCH_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | // Not sure what I am doing here, just included all the below in order 20 | // to get the extern working 21 | #include "omxplayer.h" 22 | #include "OMXStreamInfo.h" 23 | 24 | #include "utils/log.h" 25 | 26 | #include "DllAvUtil.h" 27 | #include "DllAvFormat.h" 28 | #include "DllAvFilter.h" 29 | #include "DllAvCodec.h" 30 | #include "linux/RBP.h" 31 | 32 | #include "OMXVideo.h" 33 | #include "OMXAudioCodecOMX.h" 34 | #include "utils/PCMRemap.h" 35 | #include "OMXClock.h" 36 | #include "OMXAudio.h" 37 | #include "OMXReader.h" 38 | #include "OMXPlayerVideo.h" 39 | #include "OMXPlayerAudio.h" 40 | #include "OMXPlayerSubtitles.h" 41 | // #include "OMXControl.h" 42 | #include "DllOMX.h" 43 | #include "Srt.h" 44 | // #include "KeyConfig.h" 45 | #include "utils/Strprintf.h" 46 | // #include "Keyboard.h" 47 | 48 | #include 49 | 50 | #include "version.h" 51 | 52 | using namespace std; 53 | 54 | #define JITTER_DELTA 0.01 55 | #define JITTER_TOLERANCE 10000 56 | #define CONNECT_SLEEP_PERIOD ( 1 * 1000 ) 57 | #define UPDATE_THRESHOLD 100 58 | #define BUFFLEN 4096 59 | #define MAX_NUM_CLIENT_SOCKETS 100 60 | #define LOOP_UNTIL_CONNECT 61 | 62 | typedef enum 63 | { 64 | SYNC_SERVER = 1, 65 | SYNC_CLIENT 66 | } SyncType; 67 | 68 | typedef enum 69 | { 70 | AHEAD = 1, 71 | BEHIND, 72 | ONTRACK 73 | } SyncTimeState; 74 | 75 | extern OMXClock *m_av_clock; 76 | extern OMXPlayerVideo m_player_video; 77 | 78 | // static void SetSpeed(int iSpeed); 79 | 80 | class OMXPlayerSync 81 | { 82 | public: 83 | OMXPlayerSync( SyncType _syncType, int _numNodes, int _port ); 84 | OMXPlayerSync( SyncType _syncType, int _port, const string &_serverAddress ); 85 | ~OMXPlayerSync(); 86 | void setPort ( int _port ); 87 | int setUpConnection (); 88 | int closeConnection (); 89 | int atFadingIn (); 90 | int atFadingOut (); 91 | int atPlayUnpause (); 92 | int syncServer (); 93 | int syncClient ( bool send ); 94 | int ServerBcast(); 95 | void update ( int src_alpha ); 96 | void reset (); 97 | void updateJitter (); 98 | void updateSpeed (); 99 | float getJitter (); 100 | // double getServerTime (); 101 | // int setServerTime ( double _serverTime ); 102 | // int setClientTime ( double _clientTime ); 103 | void start ( bool pause ); 104 | void pauseMovie (); 105 | void unpauseMovie (); 106 | void display (); 107 | void displayVerbose (); 108 | 109 | private: 110 | SyncType syncType; 111 | SyncTimeState syncTimeState; 112 | float jitter; 113 | double serverTime; 114 | double clientTime; 115 | int numNodes; 116 | int port; 117 | int alpha; 118 | string serverAddress; 119 | 120 | //server info 121 | int sockfd; 122 | int clientSocket [ MAX_NUM_CLIENT_SOCKETS ]; 123 | int acceptfd; 124 | int forceRebind; 125 | struct sockaddr_in server; 126 | struct sockaddr_in client; 127 | socklen_t clientaddrlen; 128 | ssize_t bytesreceived; 129 | char buff [ BUFFLEN ]; 130 | char * reply; 131 | int updateTicker; //time not reliable, use ticks instead 132 | 133 | //additional client info 134 | // char *hostname; 135 | struct addrinfo *serverinfo; 136 | char *question; 137 | bool pause; 138 | }; 139 | #endif // #ifndef OMXPLAYERSYNCH_H 140 | -------------------------------------------------------------------------------- /utils/FunctorVisitor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Author: Torarin Hals Bakke (2012) 4 | 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | 29 | #include 30 | #include 31 | 32 | #include "utils/traits.hpp" 33 | 34 | namespace functor_visitor_impl 35 | { 36 | template 37 | using arg_type = typename utils::function_traits::template arg<0>::type; 38 | 39 | template 40 | class op_call; 41 | 42 | template 43 | class op_call>::value>::type> 45 | { 46 | T fun; 47 | 48 | public: 49 | template 50 | op_call(U&& u) 51 | : fun(std::forward(u)) 52 | {} 53 | 54 | void operator()(arg_type t) { 55 | fun(std::forward>(t)); 56 | } 57 | }; 58 | 59 | template 60 | class op_call>::value>::type> 62 | { 63 | T fun; 64 | 65 | public: 66 | template 67 | op_call(U&& u) 68 | : fun(std::forward(u)) 69 | {} 70 | 71 | void operator()(const typename std::remove_cv>::type& t) { 72 | fun(t); 73 | } 74 | 75 | void operator()(const volatile arg_type& t) { 76 | fun(t); 77 | } 78 | 79 | void operator()(typename std::remove_cv>::type&& t) { 80 | fun(std::move(t)); 81 | } 82 | 83 | void operator()(volatile typename std::remove_cv>::type&& t) { 84 | fun(std::move(t)); 85 | } 86 | 87 | void operator()(const typename std::remove_cv>::type&& t) { 88 | fun(std::move(t)); 89 | } 90 | 91 | void operator()(const volatile arg_type&& t) { 92 | fun(std::move(t)); 93 | } 94 | }; 95 | } 96 | 97 | template 98 | struct functor_visitor; 99 | 100 | template <> 101 | struct functor_visitor<> { 102 | void operator()(struct dummy_type); 103 | typedef void result_type; 104 | }; 105 | 106 | template 107 | struct functor_visitor 108 | : functor_visitor_impl::op_call, 109 | functor_visitor 110 | { 111 | template 112 | functor_visitor(U&& u, Us&&... us) 113 | : functor_visitor_impl::op_call(std::forward(u)), 114 | functor_visitor(std::forward(us)...) 115 | {} 116 | 117 | using functor_visitor::operator(); 118 | using functor_visitor_impl::op_call::operator(); 119 | }; 120 | -------------------------------------------------------------------------------- /OMXOverlayCodecText.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2008 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #include "system.h" 23 | #include "OMXOverlayCodecText.h" 24 | #include "OMXOverlayText.h" 25 | #include "OMXStreamInfo.h" 26 | #include "utils/log.h" 27 | #include "OMXSubtitleTagSami.h" 28 | 29 | COMXOverlayCodecText::COMXOverlayCodecText() : COMXOverlayCodec("Text Subtitle Decoder") 30 | { 31 | m_pOverlay = NULL; 32 | m_bIsSSA = false; 33 | } 34 | 35 | COMXOverlayCodecText::~COMXOverlayCodecText() 36 | { 37 | if(m_pOverlay) 38 | delete m_pOverlay; 39 | m_pOverlay = NULL; 40 | } 41 | 42 | bool COMXOverlayCodecText::Open(COMXStreamInfo &hints) 43 | { 44 | m_bIsSSA = (hints.codec == AV_CODEC_ID_SSA); 45 | if(hints.codec == AV_CODEC_ID_SUBRIP || hints.codec == AV_CODEC_ID_SSA) 46 | return true; 47 | return false; 48 | } 49 | 50 | void COMXOverlayCodecText::Dispose() 51 | { 52 | if(m_pOverlay) 53 | delete m_pOverlay; 54 | m_pOverlay = NULL; 55 | } 56 | 57 | int COMXOverlayCodecText::Decode(BYTE* data, int size, double pts, double duration) 58 | { 59 | if(m_pOverlay) 60 | delete m_pOverlay; 61 | m_pOverlay = NULL; 62 | 63 | m_pOverlay = new COMXOverlayText(); 64 | m_pOverlay->iPTSStartTime = 0; 65 | m_pOverlay->iPTSStopTime = 0; 66 | 67 | 68 | char *start, *end, *p; 69 | start = (char*)data; 70 | end = (char*)data + size; 71 | p = (char*)data; 72 | 73 | if (m_bIsSSA) 74 | { 75 | // currently just skip the prefixed ssa fields (8 (9?) fields) 76 | int nFieldCount = 9; 77 | while (nFieldCount > 0 && start < end) 78 | { 79 | if (*start == ',') 80 | nFieldCount--; 81 | 82 | start++; 83 | p++; 84 | } 85 | } 86 | 87 | COMXSubtitleTagSami TagConv; 88 | bool Taginit = TagConv.Init(); 89 | 90 | while(pstart) 95 | { 96 | if(Taginit) 97 | TagConv.ConvertLine(m_pOverlay, start, p-start); 98 | else 99 | m_pOverlay->AddElement(new COMXOverlayText::CElementText(start, p-start)); 100 | } 101 | start = p+1; 102 | 103 | while(*p != '}' && pstart) 117 | { 118 | if(Taginit) 119 | { 120 | TagConv.ConvertLine(m_pOverlay, start, p-start); 121 | TagConv.CloseTag(m_pOverlay); 122 | } 123 | else 124 | m_pOverlay->AddElement(new COMXOverlayText::CElementText(start, p-start)); 125 | } 126 | return OC_OVERLAY; 127 | } 128 | 129 | void COMXOverlayCodecText::Reset() 130 | { 131 | if(m_pOverlay) 132 | delete m_pOverlay; 133 | m_pOverlay = NULL; 134 | } 135 | 136 | void COMXOverlayCodecText::Flush() 137 | { 138 | if(m_pOverlay) 139 | delete m_pOverlay; 140 | m_pOverlay = NULL; 141 | } 142 | 143 | COMXOverlay* COMXOverlayCodecText::GetOverlay() 144 | { 145 | if(m_pOverlay) 146 | { 147 | COMXOverlay* overlay = m_pOverlay; 148 | m_pOverlay = NULL; 149 | return overlay; 150 | } 151 | return NULL; 152 | } 153 | -------------------------------------------------------------------------------- /OMXVideo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | * Copyright (C) 2010 Team XBMC 4 | * http://www.xbmc.org 5 | * 6 | * This Program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2, or (at your option) 9 | * any later version. 10 | * 11 | * This Program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with XBMC; see the file COPYING. If not, write to 18 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 19 | * http://www.gnu.org/copyleft/gpl.html 20 | * 21 | */ 22 | 23 | #if defined(HAVE_OMXLIB) 24 | 25 | #include "OMXCore.h" 26 | #include "OMXStreamInfo.h" 27 | 28 | #include 29 | 30 | #include "OMXClock.h" 31 | #include "OMXReader.h" 32 | 33 | #include "guilib/Geometry.h" 34 | #include "utils/SingleLock.h" 35 | 36 | #define VIDEO_BUFFERS 60 37 | 38 | enum EDEINTERLACEMODE 39 | { 40 | VS_DEINTERLACEMODE_OFF=0, 41 | VS_DEINTERLACEMODE_AUTO=1, 42 | VS_DEINTERLACEMODE_FORCE=2 43 | }; 44 | 45 | #define CLASSNAME "COMXVideo" 46 | 47 | class DllAvUtil; 48 | class DllAvFormat; 49 | class COMXVideo 50 | { 51 | public: 52 | COMXVideo(); 53 | ~COMXVideo(); 54 | 55 | // Required overrides 56 | bool SendDecoderConfig(); 57 | bool NaluFormatStartCodes(enum AVCodecID codec, uint8_t *in_extradata, int in_extrasize); 58 | bool Open(COMXStreamInfo &hints, OMXClock *clock, const CRect &m_DestRect, float display_aspect = 0.0f, EDEINTERLACEMODE deinterlace = VS_DEINTERLACEMODE_OFF, bool hdmi_clock_sync = false, int layer = 0, float fifo_size = 0.0f); 59 | bool PortSettingsChanged(); 60 | bool SetAlpha( int alpha ); 61 | void Close(void); 62 | unsigned int GetFreeSpace(); 63 | unsigned int GetSize(); 64 | OMXPacket *GetText(); 65 | int DecodeText(uint8_t *pData, int iSize, double dts, double pts); 66 | int Decode(uint8_t *pData, int iSize, double pts); 67 | void Reset(void); 68 | void SetDropState(bool bDrop); 69 | std::string GetDecoderName() { return m_video_codec_name; }; 70 | void SetVideoRect(const CRect& SrcRect, const CRect& DestRect); 71 | int GetInputBufferSize(); 72 | void SubmitEOS(); 73 | bool IsEOS(); 74 | bool SubmittedEOS() { return m_submitted_eos; } 75 | bool BadState() { return m_omx_decoder.BadState(); }; 76 | protected: 77 | // Video format 78 | bool m_drop_state; 79 | unsigned int m_decoded_width; 80 | unsigned int m_decoded_height; 81 | float m_display_pixel_aspect; 82 | 83 | OMX_VIDEO_CODINGTYPE m_codingType; 84 | 85 | COMXCoreComponent m_omx_text; 86 | COMXCoreComponent m_omx_decoder; 87 | COMXCoreComponent m_omx_render; 88 | COMXCoreComponent m_omx_sched; 89 | COMXCoreComponent m_omx_image_fx; 90 | COMXCoreComponent *m_omx_clock; 91 | OMXClock *m_av_clock; 92 | 93 | COMXCoreTunel m_omx_tunnel_text; 94 | COMXCoreTunel m_omx_tunnel_decoder; 95 | COMXCoreTunel m_omx_tunnel_clock; 96 | COMXCoreTunel m_omx_tunnel_sched; 97 | COMXCoreTunel m_omx_tunnel_image_fx; 98 | bool m_is_open; 99 | 100 | bool m_setStartTime; 101 | bool m_setStartTimeText; 102 | 103 | uint8_t *m_extradata; 104 | int m_extrasize; 105 | 106 | std::string m_video_codec_name; 107 | 108 | bool m_deinterlace; 109 | EDEINTERLACEMODE m_deinterlace_request; 110 | bool m_hdmi_clock_sync; 111 | bool m_first_text; 112 | CRect m_dst_rect; 113 | CRect m_src_rect; 114 | float m_pixel_aspect; 115 | bool m_submitted_eos; 116 | bool m_failed_eos; 117 | OMX_DISPLAYTRANSFORMTYPE m_transform; 118 | bool m_settings_changed; 119 | CCriticalSection m_critSection; 120 | int m_layer; 121 | }; 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /Unicode.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Digital Mars 2003 - 2009. 2 | // Authors: Walter Bright, Sean Kelly 3 | 4 | // Boost Software License - Version 1.0 - August 17th, 2003 5 | 6 | // Permission is hereby granted, free of charge, to any person or organization 7 | // obtaining a copy of the software and accompanying documentation covered by 8 | // this license (the "Software") to use, reproduce, display, distribute, 9 | // execute, and transmit the Software, and to prepare derivative works of the 10 | // Software, and to permit third-parties to whom the Software is furnished to 11 | // do so, all subject to the following: 12 | 13 | // The copyright notices in the Software and this entire statement, including 14 | // the above license grant, this restriction and the following disclaimer, 15 | // must be included in all copies of the Software, in whole or in part, and 16 | // all derivative works of the Software, unless such copies or derivative 17 | // works are solely in the form of machine-executable object code generated by 18 | // a source language processor. 19 | 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 23 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 24 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 25 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | // DEALINGS IN THE SOFTWARE. 27 | 28 | 29 | #include 30 | #include 31 | #include "Unicode.h" 32 | 33 | /*************** 34 | * Decodes and returns character starting at s[idx]. idx is advanced past the 35 | * decoded character. If the character is not well formed, an exception is 36 | * thrown and idx remains unchanged. 37 | */ 38 | 39 | char32_t decodeUtf8(const char* s, size_t len, size_t& idx) 40 | { 41 | assert(idx < len); 42 | 43 | char32_t V; 44 | size_t i = idx; 45 | char u = s[i]; 46 | 47 | if (u & 0x80) 48 | { 49 | size_t n; 50 | char u2; 51 | 52 | /* The following encodings are valid, except for the 5 and 6 byte 53 | * combinations: 54 | * 0xxxxxxx 55 | * 110xxxxx 10xxxxxx 56 | * 1110xxxx 10xxxxxx 10xxxxxx 57 | * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 58 | * 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 59 | * 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 60 | */ 61 | for (n = 1; ; n++) 62 | { 63 | if (n > 4) 64 | goto Lerr; // only do the first 4 of 6 encodings 65 | if (((u << n) & 0x80) == 0) 66 | { 67 | if (n == 1) 68 | goto Lerr; 69 | break; 70 | } 71 | } 72 | 73 | // Pick off (7 - n) significant bits of B from first byte of octet 74 | V = static_cast(u & ((1 << (7 - n)) - 1)); 75 | 76 | if (i + (n - 1) >= len) 77 | goto Lerr; // off end of string 78 | 79 | /* The following combinations are overlong, and illegal: 80 | * 1100000x (10xxxxxx) 81 | * 11100000 100xxxxx (10xxxxxx) 82 | * 11110000 1000xxxx (10xxxxxx 10xxxxxx) 83 | * 11111000 10000xxx (10xxxxxx 10xxxxxx 10xxxxxx) 84 | * 11111100 100000xx (10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx) 85 | */ 86 | u2 = s[i + 1]; 87 | if ((u & 0xFE) == 0xC0 || 88 | (u == 0xE0 && (u2 & 0xE0) == 0x80) || 89 | (u == 0xF0 && (u2 & 0xF0) == 0x80) || 90 | (u == 0xF8 && (u2 & 0xF8) == 0x80) || 91 | (u == 0xFC && (u2 & 0xFC) == 0x80)) 92 | goto Lerr; // overlong combination 93 | 94 | for (size_t j = 1; j != n; j++) 95 | { 96 | u = s[i + j]; 97 | if ((u & 0xC0) != 0x80) 98 | goto Lerr; // trailing bytes are 10xxxxxx 99 | V = (V << 6) | (u & 0x3F); 100 | } 101 | if (!isValidChar32(V)) 102 | goto Lerr; 103 | i += n; 104 | } 105 | else 106 | { 107 | V = static_cast(u); 108 | i++; 109 | } 110 | 111 | idx = i; 112 | assert(isValidChar32(V)); 113 | return V; 114 | 115 | Lerr: 116 | throw std::runtime_error("invalid UTF-8 sequence"); 117 | return V; // dummy return 118 | } 119 | -------------------------------------------------------------------------------- /guilib/Geometry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2008 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifdef __GNUC__ 25 | // under gcc, inline will only take place if optimizations are applied (-O). this will force inline even whith optimizations. 26 | #define XBMC_FORCE_INLINE __attribute__((always_inline)) 27 | #else 28 | #define XBMC_FORCE_INLINE 29 | #endif 30 | #include 31 | 32 | class CPoint 33 | { 34 | public: 35 | CPoint() 36 | { 37 | x = 0; y = 0; 38 | }; 39 | 40 | CPoint(float a, float b) 41 | { 42 | x = a; 43 | y = b; 44 | }; 45 | 46 | CPoint operator+(const CPoint &point) const 47 | { 48 | CPoint ans; 49 | ans.x = x + point.x; 50 | ans.y = y + point.y; 51 | return ans; 52 | }; 53 | 54 | const CPoint &operator+=(const CPoint &point) 55 | { 56 | x += point.x; 57 | y += point.y; 58 | return *this; 59 | }; 60 | 61 | CPoint operator-(const CPoint &point) const 62 | { 63 | CPoint ans; 64 | ans.x = x - point.x; 65 | ans.y = y - point.y; 66 | return ans; 67 | }; 68 | 69 | const CPoint &operator-=(const CPoint &point) 70 | { 71 | x -= point.x; 72 | y -= point.y; 73 | return *this; 74 | }; 75 | 76 | float x, y; 77 | }; 78 | 79 | class CRect 80 | { 81 | public: 82 | CRect() { x1 = y1 = x2 = y2 = 0;}; 83 | CRect(float left, float top, float right, float bottom) { x1 = left; y1 = top; x2 = right; y2 = bottom; }; 84 | 85 | void SetRect(float left, float top, float right, float bottom) { x1 = left; y1 = top; x2 = right; y2 = bottom; }; 86 | 87 | bool PtInRect(const CPoint &point) const 88 | { 89 | if (x1 <= point.x && point.x <= x2 && y1 <= point.y && point.y <= y2) 90 | return true; 91 | return false; 92 | }; 93 | 94 | inline const CRect &operator -=(const CPoint &point) XBMC_FORCE_INLINE 95 | { 96 | x1 -= point.x; 97 | y1 -= point.y; 98 | x2 -= point.x; 99 | y2 -= point.y; 100 | return *this; 101 | }; 102 | 103 | inline const CRect &operator +=(const CPoint &point) XBMC_FORCE_INLINE 104 | { 105 | x1 += point.x; 106 | y1 += point.y; 107 | x2 += point.x; 108 | y2 += point.y; 109 | return *this; 110 | }; 111 | 112 | const CRect &Intersect(const CRect &rect) 113 | { 114 | x1 = clamp_range(x1, rect.x1, rect.x2); 115 | x2 = clamp_range(x2, rect.x1, rect.x2); 116 | y1 = clamp_range(y1, rect.y1, rect.y2); 117 | y2 = clamp_range(y2, rect.y1, rect.y2); 118 | return *this; 119 | }; 120 | 121 | const CRect &Union(const CRect &rect) 122 | { 123 | if (IsEmpty()) 124 | *this = rect; 125 | else if (!rect.IsEmpty()) 126 | { 127 | x1 = std::min(x1,rect.x1); 128 | y1 = std::min(y1,rect.y1); 129 | 130 | x2 = std::max(x2,rect.x2); 131 | y2 = std::max(y2,rect.y2); 132 | } 133 | 134 | return *this; 135 | }; 136 | 137 | inline bool IsEmpty() const XBMC_FORCE_INLINE 138 | { 139 | return (x2 - x1) * (y2 - y1) == 0; 140 | }; 141 | 142 | inline float Width() const XBMC_FORCE_INLINE 143 | { 144 | return x2 - x1; 145 | }; 146 | 147 | inline float Height() const XBMC_FORCE_INLINE 148 | { 149 | return y2 - y1; 150 | }; 151 | 152 | inline float Area() const XBMC_FORCE_INLINE 153 | { 154 | return Width() * Height(); 155 | }; 156 | 157 | bool operator !=(const CRect &rect) const 158 | { 159 | if (x1 != rect.x1) return true; 160 | if (x2 != rect.x2) return true; 161 | if (y1 != rect.y1) return true; 162 | if (y2 != rect.y2) return true; 163 | return false; 164 | }; 165 | 166 | float x1, y1, x2, y2; 167 | private: 168 | inline static float clamp_range(float x, float l, float h) XBMC_FORCE_INLINE 169 | { 170 | return (x > h) ? h : ((x < l) ? l : x); 171 | } 172 | }; 173 | 174 | -------------------------------------------------------------------------------- /Keyboard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "utils/log.h" 12 | #include "Keyboard.h" 13 | 14 | Keyboard::Keyboard() 15 | { 16 | if (isatty(STDIN_FILENO)) 17 | { 18 | struct termios new_termios; 19 | 20 | tcgetattr(STDIN_FILENO, &orig_termios); 21 | 22 | new_termios = orig_termios; 23 | new_termios.c_lflag &= ~(ICANON | ECHO | ECHOCTL | ECHONL); 24 | new_termios.c_cflag |= HUPCL; 25 | new_termios.c_cc[VMIN] = 0; 26 | 27 | tcsetattr(STDIN_FILENO, TCSANOW, &new_termios); 28 | } 29 | else 30 | { 31 | orig_fl = fcntl(STDIN_FILENO, F_GETFL); 32 | fcntl(STDIN_FILENO, F_SETFL, orig_fl | O_NONBLOCK); 33 | } 34 | 35 | if (dbus_connect() < 0) 36 | { 37 | CLog::Log(LOGWARNING, "DBus connection failed"); 38 | } 39 | else 40 | { 41 | CLog::Log(LOGDEBUG, "DBus connection succeeded"); 42 | } 43 | 44 | dbus_threads_init_default(); 45 | Create(); 46 | } 47 | 48 | Keyboard::~Keyboard() 49 | { 50 | Close(); 51 | } 52 | 53 | void Keyboard::Close() 54 | { 55 | restore_term(); 56 | dbus_disconnect(); 57 | if (ThreadHandle()) 58 | { 59 | StopThread(); 60 | } 61 | } 62 | 63 | void Keyboard::restore_term() 64 | { 65 | if (isatty(STDIN_FILENO)) 66 | { 67 | tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios); 68 | } 69 | else 70 | { 71 | fcntl(STDIN_FILENO, F_SETFL, orig_fl); 72 | } 73 | } 74 | 75 | void Keyboard::Sleep(unsigned int dwMilliSeconds) 76 | { 77 | struct timespec req; 78 | req.tv_sec = dwMilliSeconds / 1000; 79 | req.tv_nsec = (dwMilliSeconds % 1000) * 1000000; 80 | 81 | while ( nanosleep(&req, &req) == -1 && errno == EINTR && (req.tv_nsec > 0 || req.tv_sec > 0)); 82 | } 83 | 84 | void Keyboard::Process() 85 | { 86 | while(!m_bStop && conn && dbus_connection_read_write_dispatch(conn, 0)) 87 | { 88 | int ch[8]; 89 | int chnum = 0; 90 | 91 | while ((ch[chnum] = getchar()) != EOF) chnum++; 92 | 93 | if (chnum > 1) ch[0] = ch[chnum - 1] | (ch[chnum - 2] << 8); 94 | 95 | if (m_keymap[ch[0]] != 0) 96 | send_action(m_keymap[ch[0]]); 97 | else 98 | Sleep(20); 99 | } 100 | } 101 | 102 | void Keyboard::send_action(int action) 103 | { 104 | DBusMessage *message = NULL, *reply = NULL; 105 | DBusError error; 106 | 107 | dbus_error_init(&error); 108 | 109 | if (!(message = dbus_message_new_method_call(m_dbus_name.c_str(), 110 | OMXPLAYER_DBUS_PATH_SERVER, 111 | OMXPLAYER_DBUS_INTERFACE_PLAYER, 112 | "Action"))) 113 | { 114 | CLog::Log(LOGWARNING, "Keyboard: DBus error 1"); 115 | goto fail; 116 | } 117 | 118 | dbus_message_append_args(message, DBUS_TYPE_INT32, &action, DBUS_TYPE_INVALID); 119 | 120 | reply = dbus_connection_send_with_reply_and_block(conn, message, -1, &error); 121 | 122 | if (!reply || dbus_error_is_set(&error)) 123 | goto fail; 124 | 125 | dbus_message_unref(message); 126 | dbus_message_unref(reply); 127 | 128 | return; 129 | 130 | fail: 131 | if (dbus_error_is_set(&error)) 132 | { 133 | printf("%s", error.message); 134 | dbus_error_free(&error); 135 | } 136 | 137 | if (message) 138 | dbus_message_unref(message); 139 | 140 | if (reply) 141 | dbus_message_unref(reply); 142 | } 143 | 144 | void Keyboard::setKeymap(std::map keymap) 145 | { 146 | m_keymap = keymap; 147 | } 148 | 149 | void Keyboard::setDbusName(std::string dbus_name) 150 | { 151 | m_dbus_name = dbus_name; 152 | } 153 | 154 | int Keyboard::dbus_connect() 155 | { 156 | DBusError error; 157 | 158 | dbus_error_init(&error); 159 | if (!(conn = dbus_bus_get_private(DBUS_BUS_SESSION, &error))) 160 | { 161 | CLog::Log(LOGWARNING, "dbus_bus_get_private(): %s", error.message); 162 | goto fail; 163 | } 164 | 165 | dbus_connection_set_exit_on_disconnect(conn, FALSE); 166 | 167 | return 0; 168 | 169 | fail: 170 | if (dbus_error_is_set(&error)) 171 | dbus_error_free(&error); 172 | 173 | if (conn) 174 | { 175 | dbus_connection_close(conn); 176 | dbus_connection_unref(conn); 177 | conn = NULL; 178 | } 179 | 180 | return -1; 181 | 182 | } 183 | 184 | void Keyboard::dbus_disconnect() 185 | { 186 | if (conn) 187 | { 188 | dbus_connection_close(conn); 189 | dbus_connection_unref(conn); 190 | conn = NULL; 191 | } 192 | } -------------------------------------------------------------------------------- /File.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * XBMC Media Center 3 | * Copyright (c) 2002 Frodo 4 | * Portions Copyright (c) by the authors of ffmpeg and xvid 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | */ 20 | 21 | #include "linux/PlatformDefs.h" 22 | #include 23 | #include 24 | #include "utils/StdString.h" 25 | 26 | #include "File.h" 27 | 28 | using namespace XFILE; 29 | using namespace std; 30 | 31 | ////////////////////////////////////////////////////////////////////// 32 | // Construction/Destruction 33 | ////////////////////////////////////////////////////////////////////// 34 | #ifndef __GNUC__ 35 | #pragma warning (disable:4244) 36 | #endif 37 | 38 | //********************************************************************************************* 39 | CFile::CFile() 40 | { 41 | m_pFile = NULL; 42 | m_flags = 0; 43 | m_iLength = 0; 44 | m_bPipe = false; 45 | } 46 | 47 | //********************************************************************************************* 48 | CFile::~CFile() 49 | { 50 | if(m_pFile && !m_bPipe) 51 | fclose(m_pFile); 52 | } 53 | 54 | //********************************************************************************************* 55 | bool CFile::Open(const CStdString& strFileName, unsigned int flags) 56 | { 57 | m_flags = flags; 58 | 59 | if (strFileName.compare(0, 5, "pipe:") == 0) 60 | { 61 | m_bPipe = true; 62 | m_pFile = stdin; 63 | m_iLength = 0; 64 | return true; 65 | } 66 | m_pFile = fopen64(strFileName.c_str(), "r"); 67 | if(!m_pFile) 68 | return false; 69 | 70 | fseeko64(m_pFile, 0, SEEK_END); 71 | m_iLength = ftello64(m_pFile); 72 | fseeko64(m_pFile, 0, SEEK_SET); 73 | 74 | return true; 75 | } 76 | 77 | bool CFile::OpenForWrite(const CStdString& strFileName, bool bOverWrite) 78 | { 79 | return false; 80 | } 81 | 82 | bool CFile::Exists(const CStdString& strFileName, bool bUseCache /* = true */) 83 | { 84 | FILE *fp; 85 | 86 | if (strFileName.compare(0, 5, "pipe:") == 0) 87 | return true; 88 | 89 | fp = fopen64(strFileName.c_str(), "r"); 90 | 91 | if(!fp) 92 | return false; 93 | 94 | fclose(fp); 95 | 96 | return true; 97 | } 98 | 99 | unsigned int CFile::Read(void *lpBuf, int64_t uiBufSize) 100 | { 101 | unsigned int ret = 0; 102 | 103 | if(!m_pFile) 104 | return 0; 105 | 106 | ret = fread(lpBuf, 1, uiBufSize, m_pFile); 107 | 108 | return ret; 109 | } 110 | 111 | //********************************************************************************************* 112 | void CFile::Close() 113 | { 114 | if(m_pFile && !m_bPipe) 115 | fclose(m_pFile); 116 | m_pFile = NULL; 117 | } 118 | 119 | //********************************************************************************************* 120 | int64_t CFile::Seek(int64_t iFilePosition, int iWhence) 121 | { 122 | if (!m_pFile) 123 | return -1; 124 | 125 | return fseeko64(m_pFile, iFilePosition, iWhence);; 126 | } 127 | 128 | //********************************************************************************************* 129 | int64_t CFile::GetLength() 130 | { 131 | return m_iLength; 132 | } 133 | 134 | //********************************************************************************************* 135 | int64_t CFile::GetPosition() 136 | { 137 | if (!m_pFile) 138 | return -1; 139 | 140 | return ftello64(m_pFile); 141 | } 142 | 143 | //********************************************************************************************* 144 | int CFile::Write(const void* lpBuf, int64_t uiBufSize) 145 | { 146 | return -1; 147 | } 148 | 149 | int CFile::IoControl(EIoControl request, void* param) 150 | { 151 | if(request == IOCTRL_SEEK_POSSIBLE && m_pFile) 152 | { 153 | if (m_bPipe) 154 | return false; 155 | 156 | struct stat st; 157 | if (fstat(fileno(m_pFile), &st) == 0) 158 | { 159 | return !S_ISFIFO(st.st_mode); 160 | } 161 | } 162 | 163 | return -1; 164 | } 165 | 166 | bool CFile::IsEOF() 167 | { 168 | if (!m_pFile) 169 | return -1; 170 | 171 | if (m_bPipe) 172 | return false; 173 | 174 | return feof(m_pFile) != 0; 175 | } 176 | -------------------------------------------------------------------------------- /OMXPlayerVideo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2008 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #ifndef _OMX_PLAYERVIDEO_H_ 23 | #define _OMX_PLAYERVIDEO_H_ 24 | 25 | #include "DllAvUtil.h" 26 | #include "DllAvFormat.h" 27 | #include "DllAvFilter.h" 28 | #include "DllAvCodec.h" 29 | 30 | #include "OMXReader.h" 31 | #include "OMXClock.h" 32 | #include "OMXStreamInfo.h" 33 | #include "OMXVideo.h" 34 | #include "OMXThread.h" 35 | 36 | #include 37 | #include 38 | 39 | #include "OMXOverlayCodec.h" 40 | #include "OMXOverlayText.h" 41 | #include "OMXOverlayCodecText.h" 42 | 43 | #include 44 | #include 45 | 46 | using namespace std; 47 | 48 | class OMXPlayerVideo : public OMXThread 49 | { 50 | protected: 51 | AVStream *m_pStream; 52 | int m_stream_id; 53 | std::deque m_subtitle_packets; 54 | std::deque m_packets; 55 | std::deque m_overlays; 56 | DllAvUtil m_dllAvUtil; 57 | DllAvCodec m_dllAvCodec; 58 | DllAvFormat m_dllAvFormat; 59 | bool m_open; 60 | COMXStreamInfo m_hints; 61 | double m_iCurrentPts; 62 | pthread_cond_t m_packet_cond; 63 | pthread_cond_t m_picture_cond; 64 | pthread_mutex_t m_lock; 65 | pthread_mutex_t m_subtitle; 66 | pthread_mutex_t m_lock_decoder; 67 | pthread_mutex_t m_lock_subtitle; 68 | OMXClock *m_av_clock; 69 | COMXVideo *m_decoder; 70 | float m_fps; 71 | double m_frametime; 72 | EDEINTERLACEMODE m_Deinterlace; 73 | float m_display_aspect; 74 | CRect m_DestRect; 75 | bool m_bAbort; 76 | bool m_use_thread; 77 | bool m_flush; 78 | std::atomic m_flush_requested; 79 | unsigned int m_cached_size; 80 | unsigned int m_max_data_size; 81 | float m_fifo_size; 82 | bool m_hdmi_clock_sync; 83 | double m_iVideoDelay; 84 | double m_iSubtitleDelay; 85 | COMXOverlayCodec *m_pSubtitleCodec; 86 | uint32_t m_history_valid_pts; 87 | int m_layer; 88 | 89 | void Lock(); 90 | void UnLock(); 91 | void LockDecoder(); 92 | void UnLockDecoder(); 93 | void LockSubtitles(); 94 | void UnLockSubtitles(); 95 | private: 96 | public: 97 | OMXPlayerVideo(); 98 | ~OMXPlayerVideo(); 99 | bool Open(COMXStreamInfo &hints, OMXClock *av_clock, const CRect& DestRect, EDEINTERLACEMODE deinterlace, bool hdmi_clock_sync, bool use_thread, 100 | float display_aspect, int layer, float queue_size, float fifo_size); 101 | bool Close(); 102 | bool Decode(OMXPacket *pkt); 103 | void Process(); 104 | void FlushSubtitles(); 105 | void Flush(); 106 | bool AddPacket(OMXPacket *pkt); 107 | bool OpenDecoder(); 108 | bool SetAlpha( int alpha ); 109 | bool CloseDecoder(); 110 | int GetDecoderBufferSize(); 111 | int GetDecoderFreeSpace(); 112 | double GetCurrentPTS() { return m_iCurrentPts; }; 113 | double GetFPS() { return m_fps; }; 114 | unsigned int GetCached() { return m_cached_size; }; 115 | unsigned int GetMaxCached() { return m_max_data_size; }; 116 | unsigned int GetLevel() { return m_max_data_size ? 100 * m_cached_size / m_max_data_size : 0; }; 117 | void SubmitEOS(); 118 | bool IsEOS(); 119 | void SetDelay(double delay) { m_iVideoDelay = delay; } 120 | double GetDelay() { return m_iVideoDelay; } 121 | double GetSubtitleDelay() { return m_iSubtitleDelay; } 122 | void SetSubtitleDelay(double delay) { m_iSubtitleDelay = delay; } 123 | std::string GetText(); 124 | }; 125 | #endif 126 | -------------------------------------------------------------------------------- /OMXPlayerAudio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2008 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #ifndef _OMX_PLAYERAUDIO_H_ 23 | #define _OMX_PLAYERAUDIO_H_ 24 | 25 | #include "DllAvUtil.h" 26 | #include "DllAvFormat.h" 27 | #include "DllAvFilter.h" 28 | #include "DllAvCodec.h" 29 | 30 | #include "utils/PCMRemap.h" 31 | 32 | #include "OMXReader.h" 33 | #include "OMXClock.h" 34 | #include "OMXStreamInfo.h" 35 | #include "OMXAudio.h" 36 | #include "OMXAudioCodecOMX.h" 37 | #include "OMXThread.h" 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | using namespace std; 45 | 46 | class OMXPlayerAudio : public OMXThread 47 | { 48 | protected: 49 | AVStream *m_pStream; 50 | int m_stream_id; 51 | std::deque m_packets; 52 | DllAvUtil m_dllAvUtil; 53 | DllAvCodec m_dllAvCodec; 54 | DllAvFormat m_dllAvFormat; 55 | bool m_open; 56 | COMXStreamInfo m_hints; 57 | double m_iCurrentPts; 58 | pthread_cond_t m_packet_cond; 59 | pthread_cond_t m_audio_cond; 60 | pthread_mutex_t m_lock; 61 | pthread_mutex_t m_lock_decoder; 62 | OMXClock *m_av_clock; 63 | OMXReader *m_omx_reader; 64 | COMXAudio *m_decoder; 65 | std::string m_codec_name; 66 | std::string m_device; 67 | bool m_use_passthrough; 68 | bool m_use_hw_decode; 69 | bool m_passthrough; 70 | bool m_hw_decode; 71 | bool m_boost_on_downmix; 72 | bool m_bAbort; 73 | bool m_use_thread; 74 | bool m_flush; 75 | std::atomic m_flush_requested; 76 | bool m_live; 77 | enum PCMLayout m_layout; 78 | unsigned int m_cached_size; 79 | unsigned int m_max_data_size; 80 | float m_fifo_size; 81 | COMXAudioCodecOMX *m_pAudioCodec; 82 | float m_CurrentVolume; 83 | long m_amplification; 84 | bool m_mute; 85 | bool m_player_error; 86 | 87 | void Lock(); 88 | void UnLock(); 89 | void LockDecoder(); 90 | void UnLockDecoder(); 91 | private: 92 | public: 93 | OMXPlayerAudio(); 94 | ~OMXPlayerAudio(); 95 | bool Open(COMXStreamInfo &hints, OMXClock *av_clock, OMXReader *omx_reader, 96 | std::string device, bool passthrough, bool hw_decode, 97 | bool boost_on_downmix, bool use_thread, bool is_live, enum PCMLayout layout, float queue_size, float fifo_size); 98 | bool Close(); 99 | bool Decode(OMXPacket *pkt); 100 | void Process(); 101 | void Flush(); 102 | bool AddPacket(OMXPacket *pkt); 103 | bool OpenAudioCodec(); 104 | void CloseAudioCodec(); 105 | bool IsPassthrough(COMXStreamInfo hints); 106 | bool OpenDecoder(); 107 | bool CloseDecoder(); 108 | double GetDelay(); 109 | double GetCacheTime(); 110 | double GetCacheTotal(); 111 | double GetCurrentPTS() { return m_iCurrentPts; }; 112 | void SubmitEOS(); 113 | bool IsEOS(); 114 | void WaitCompletion(); 115 | unsigned int GetCached() { return m_cached_size; }; 116 | unsigned int GetMaxCached() { return m_max_data_size; }; 117 | unsigned int GetLevel() { return m_max_data_size ? 100 * m_cached_size / m_max_data_size : 0; }; 118 | void SetVolume(float fVolume) { m_CurrentVolume = fVolume; if(m_decoder) m_decoder->SetVolume(fVolume); } 119 | float GetVolume() { return m_CurrentVolume; } 120 | void SetMute(bool bOnOff) { m_mute = bOnOff; if(m_decoder) m_decoder->SetMute(bOnOff); } 121 | void SetDynamicRangeCompression(long drc) { m_amplification = drc; if(m_decoder) m_decoder->SetDynamicRangeCompression(drc); } 122 | bool Error() { return !m_player_error; }; 123 | }; 124 | #endif 125 | -------------------------------------------------------------------------------- /DllOMX.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | * Copyright (C) 2005-2010 Team XBMC 4 | * http://www.xbmc.org 5 | * 6 | * This Program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2, or (at your option) 9 | * any later version. 10 | * 11 | * This Program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with XBMC; see the file COPYING. If not, write to 18 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 19 | * http://www.gnu.org/copyleft/gpl.html 20 | * 21 | */ 22 | 23 | #if defined(HAVE_OMXLIB) 24 | 25 | #if (defined HAVE_CONFIG_H) && (!defined WIN32) 26 | #include "config.h" 27 | #endif 28 | #ifndef __GNUC__ 29 | #pragma warning(push) 30 | #pragma warning(disable:4244) 31 | #endif 32 | 33 | #include "DynamicDll.h" 34 | #include "utils/log.h" 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | //////////////////////////////////////////////////////////////////////////////////////////// 44 | 45 | class DllOMXInterface 46 | { 47 | public: 48 | virtual ~DllOMXInterface() {} 49 | 50 | virtual OMX_ERRORTYPE OMX_Init(void) = 0; 51 | virtual OMX_ERRORTYPE OMX_Deinit(void) = 0; 52 | virtual OMX_ERRORTYPE OMX_GetHandle(OMX_HANDLETYPE *pHandle, OMX_STRING cComponentName, OMX_PTR pAppData, OMX_CALLBACKTYPE *pCallBacks) = 0; 53 | virtual OMX_ERRORTYPE OMX_FreeHandle(OMX_HANDLETYPE hComponent) = 0; 54 | virtual OMX_ERRORTYPE OMX_GetComponentsOfRole(OMX_STRING role, OMX_U32 *pNumComps, OMX_U8 **compNames) = 0; 55 | virtual OMX_ERRORTYPE OMX_GetRolesOfComponent(OMX_STRING compName, OMX_U32 *pNumRoles, OMX_U8 **roles) = 0; 56 | virtual OMX_ERRORTYPE OMX_ComponentNameEnum(OMX_STRING cComponentName, OMX_U32 nNameLength, OMX_U32 nIndex) = 0; 57 | virtual OMX_ERRORTYPE OMX_SetupTunnel(OMX_HANDLETYPE hOutput, OMX_U32 nPortOutput, OMX_HANDLETYPE hInput, OMX_U32 nPortInput) = 0; 58 | 59 | }; 60 | 61 | #if (defined USE_EXTERNAL_OMX) 62 | class DllOMX : public DllDynamic, DllOMXInterface 63 | { 64 | public: 65 | virtual OMX_ERRORTYPE OMX_Init(void) 66 | { return ::OMX_Init(); }; 67 | virtual OMX_ERRORTYPE OMX_Deinit(void) 68 | { return ::OMX_Deinit(); }; 69 | virtual OMX_ERRORTYPE OMX_GetHandle(OMX_HANDLETYPE *pHandle, OMX_STRING cComponentName, OMX_PTR pAppData, OMX_CALLBACKTYPE *pCallBacks) 70 | { return ::OMX_GetHandle(pHandle, cComponentName, pAppData, pCallBacks); }; 71 | virtual OMX_ERRORTYPE OMX_FreeHandle(OMX_HANDLETYPE hComponent) 72 | { return ::OMX_FreeHandle(hComponent); }; 73 | virtual OMX_ERRORTYPE OMX_GetComponentsOfRole(OMX_STRING role, OMX_U32 *pNumComps, OMX_U8 **compNames) 74 | { return ::OMX_GetComponentsOfRole(role, pNumComps, compNames); }; 75 | virtual OMX_ERRORTYPE OMX_GetRolesOfComponent(OMX_STRING compName, OMX_U32 *pNumRoles, OMX_U8 **roles) 76 | { return ::OMX_GetRolesOfComponent(compName, pNumRoles, roles); }; 77 | virtual OMX_ERRORTYPE OMX_ComponentNameEnum(OMX_STRING cComponentName, OMX_U32 nNameLength, OMX_U32 nIndex) 78 | { return ::OMX_ComponentNameEnum(cComponentName, nNameLength, nIndex); }; 79 | virtual OMX_ERRORTYPE OMX_SetupTunnel(OMX_HANDLETYPE hOutput, OMX_U32 nPortOutput, OMX_HANDLETYPE hInput, OMX_U32 nPortInput) 80 | { return ::OMX_SetupTunnel(hOutput, nPortOutput, hInput, nPortInput); }; 81 | virtual bool ResolveExports() 82 | { return true; } 83 | virtual bool Load() 84 | { 85 | CLog::Log(LOGDEBUG, "DllOMX: Using omx system library"); 86 | return true; 87 | } 88 | virtual void Unload() {} 89 | static DllOMX *GetDllOMX() { static DllOMX static_dll_omx; return &static_dll_omx; } 90 | }; 91 | #else 92 | class DllOMX : public DllDynamic, DllOMXInterface 93 | { 94 | //DECLARE_DLL_WRAPPER(DllLibOpenMax, "/usr/lib/libnvomx.so") 95 | DECLARE_DLL_WRAPPER(DllOMX, "/opt/vc/lib/libopenmaxil.so") 96 | 97 | DEFINE_METHOD0(OMX_ERRORTYPE, OMX_Init) 98 | DEFINE_METHOD0(OMX_ERRORTYPE, OMX_Deinit) 99 | DEFINE_METHOD4(OMX_ERRORTYPE, OMX_GetHandle, (OMX_HANDLETYPE *p1, OMX_STRING p2, OMX_PTR p3, OMX_CALLBACKTYPE *p4)) 100 | DEFINE_METHOD1(OMX_ERRORTYPE, OMX_FreeHandle, (OMX_HANDLETYPE p1)) 101 | DEFINE_METHOD3(OMX_ERRORTYPE, OMX_GetComponentsOfRole, (OMX_STRING p1, OMX_U32 *p2, OMX_U8 **p3)) 102 | DEFINE_METHOD3(OMX_ERRORTYPE, OMX_GetRolesOfComponent, (OMX_STRING p1, OMX_U32 *p2, OMX_U8 **p3)) 103 | DEFINE_METHOD3(OMX_ERRORTYPE, OMX_ComponentNameEnum, (OMX_STRING p1, OMX_U32 p2, OMX_U32 p3)) 104 | DEFINE_METHOD4(OMX_ERRORTYPE, OMX_SetupTunnel, (OMX_HANDLETYPE p1, OMX_U32 p2, OMX_HANDLETYPE p3, OMX_U32 p4)); 105 | BEGIN_METHOD_RESOLVE() 106 | RESOLVE_METHOD(OMX_Init) 107 | RESOLVE_METHOD(OMX_Deinit) 108 | RESOLVE_METHOD(OMX_GetHandle) 109 | RESOLVE_METHOD(OMX_FreeHandle) 110 | RESOLVE_METHOD(OMX_GetComponentsOfRole) 111 | RESOLVE_METHOD(OMX_GetRolesOfComponent) 112 | RESOLVE_METHOD(OMX_ComponentNameEnum) 113 | RESOLVE_METHOD(OMX_SetupTunnel) 114 | END_METHOD_RESOLVE() 115 | 116 | public: 117 | virtual bool Load() 118 | { 119 | return DllDynamic::Load(); 120 | } 121 | }; 122 | #endif 123 | 124 | #endif 125 | -------------------------------------------------------------------------------- /OMXPlayerSubtitles.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * Author: Torarin Hals Bakke (2012) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | */ 20 | 21 | #include "OMXThread.h" 22 | #include "OMXReader.h" 23 | #include "OMXClock.h" 24 | #include "OMXOverlayCodecText.h" 25 | #include "Subtitle.h" 26 | #include "utils/Mailbox.h" 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | class OMXPlayerSubtitles : public OMXThread 36 | { 37 | public: 38 | OMXPlayerSubtitles(const OMXPlayerSubtitles&) = delete; 39 | OMXPlayerSubtitles& operator=(const OMXPlayerSubtitles&) = delete; 40 | OMXPlayerSubtitles() BOOST_NOEXCEPT; 41 | ~OMXPlayerSubtitles() BOOST_NOEXCEPT; 42 | bool Open(size_t stream_count, 43 | std::vector&& external_subtitles, 44 | const std::string& font_path, 45 | const std::string& italic_font_path, 46 | float font_size, 47 | bool centered, 48 | bool ghost_box, 49 | unsigned int lines, 50 | int layer, 51 | OMXClock* clock) BOOST_NOEXCEPT; 52 | void Close() BOOST_NOEXCEPT; 53 | void Flush() BOOST_NOEXCEPT; 54 | void Resume() BOOST_NOEXCEPT; 55 | void Pause() BOOST_NOEXCEPT; 56 | 57 | void SetVisible(bool visible) BOOST_NOEXCEPT; 58 | 59 | bool GetVisible() BOOST_NOEXCEPT 60 | { 61 | assert(m_open); 62 | return m_visible; 63 | } 64 | 65 | void SetActiveStream(size_t index) BOOST_NOEXCEPT; 66 | 67 | size_t GetActiveStream() BOOST_NOEXCEPT 68 | { 69 | assert(m_open); 70 | assert(!m_subtitle_buffers.empty()); 71 | return m_active_index; 72 | } 73 | 74 | void SetDelay(int value) BOOST_NOEXCEPT; 75 | 76 | int GetDelay() BOOST_NOEXCEPT 77 | { 78 | assert(m_open); 79 | return m_delay; 80 | } 81 | 82 | void SetUseExternalSubtitles(bool use) BOOST_NOEXCEPT; 83 | 84 | bool GetUseExternalSubtitles() BOOST_NOEXCEPT 85 | { 86 | assert(m_open); 87 | return m_use_external_subtitles; 88 | } 89 | 90 | void DisplayText(const std::string& text, int duration) BOOST_NOEXCEPT; 91 | 92 | bool AddPacket(OMXPacket *pkt, size_t stream_index) BOOST_NOEXCEPT; 93 | 94 | private: 95 | struct Message { 96 | struct Stop {}; 97 | struct Flush 98 | { 99 | std::vector subtitles; 100 | }; 101 | struct Push 102 | { 103 | Subtitle subtitle; 104 | }; 105 | struct Touch {}; 106 | struct SetDelay 107 | { 108 | int value; 109 | }; 110 | struct SetPaused 111 | { 112 | bool value; 113 | }; 114 | struct DisplayText 115 | { 116 | std::vector text_lines; 117 | int duration; 118 | }; 119 | }; 120 | 121 | template 122 | void SendToRenderer(T&& msg) 123 | { 124 | if(m_thread_stopped.load(std::memory_order_relaxed)) 125 | { 126 | CLog::Log(LOGERROR, "Subtitle rendering thread not running, message discarded"); 127 | return; 128 | } 129 | m_mailbox.send(std::forward(msg)); 130 | } 131 | 132 | void Process(); 133 | void RenderLoop(const std::string& font_path, 134 | const std::string& italic_font_path, 135 | float font_size, 136 | bool centered, 137 | bool ghost_box, 138 | unsigned int lines, 139 | OMXClock* clock); 140 | std::vector GetTextLines(OMXPacket *pkt); 141 | void FlushRenderer(); 142 | 143 | COMXOverlayCodecText m_subtitle_codec; 144 | std::vector m_external_subtitles; 145 | std::vector> m_subtitle_buffers; 146 | Mailbox m_mailbox; 153 | bool m_visible; 154 | bool m_use_external_subtitles; 155 | size_t m_active_index; 156 | int m_delay; 157 | std::atomic m_thread_stopped; 158 | std::string m_font_path; 159 | std::string m_italic_font_path; 160 | float m_font_size; 161 | bool m_centered; 162 | bool m_ghost_box; 163 | unsigned int m_lines; 164 | OMXClock* m_av_clock; 165 | int m_layer; 166 | 167 | #ifndef NDEBUG 168 | bool m_open; 169 | #endif 170 | }; 171 | -------------------------------------------------------------------------------- /utils/PCMRemap.h: -------------------------------------------------------------------------------- 1 | #ifndef __PCM_REMAP__H__ 2 | #define __PCM_REMAP__H__ 3 | 4 | /* 5 | * Copyright (C) 2005-2010 Team XBMC 6 | * http://www.xbmc.org 7 | * 8 | * This Program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2, or (at your option) 11 | * any later version. 12 | * 13 | * This Program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with XBMC; see the file COPYING. If not, write to 20 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 21 | * http://www.gnu.org/copyleft/gpl.html 22 | * 23 | */ 24 | 25 | #include 26 | #include 27 | #include "StdString.h" 28 | 29 | #define PCM_MAX_CH 18 30 | enum PCMChannels 31 | { 32 | PCM_INVALID = -1, 33 | PCM_FRONT_LEFT, 34 | PCM_FRONT_RIGHT, 35 | PCM_FRONT_CENTER, 36 | PCM_LOW_FREQUENCY, 37 | PCM_BACK_LEFT, 38 | PCM_BACK_RIGHT, 39 | PCM_FRONT_LEFT_OF_CENTER, 40 | PCM_FRONT_RIGHT_OF_CENTER, 41 | PCM_BACK_CENTER, 42 | PCM_SIDE_LEFT, 43 | PCM_SIDE_RIGHT, 44 | PCM_TOP_FRONT_LEFT, 45 | PCM_TOP_FRONT_RIGHT, 46 | PCM_TOP_FRONT_CENTER, 47 | PCM_TOP_CENTER, 48 | PCM_TOP_BACK_LEFT, 49 | PCM_TOP_BACK_RIGHT, 50 | PCM_TOP_BACK_CENTER 51 | }; 52 | 53 | #define PCM_MAX_LAYOUT 10 54 | enum PCMLayout 55 | { 56 | PCM_LAYOUT_2_0 = 0, 57 | PCM_LAYOUT_2_1, 58 | PCM_LAYOUT_3_0, 59 | PCM_LAYOUT_3_1, 60 | PCM_LAYOUT_4_0, 61 | PCM_LAYOUT_4_1, 62 | PCM_LAYOUT_5_0, 63 | PCM_LAYOUT_5_1, 64 | PCM_LAYOUT_7_0, 65 | PCM_LAYOUT_7_1 66 | }; 67 | 68 | struct PCMMapInfo 69 | { 70 | enum PCMChannels channel; 71 | float level; 72 | bool ifExists; 73 | int in_offset; 74 | bool copy; 75 | }; 76 | 77 | //! Channels remapper class 78 | /*! 79 | The usual set-up process: 80 | - user calls SetInputFormat with the input channels information 81 | - SetInputFormat responds with a channelmap corresponding to the speaker 82 | layout that the user has configured, with empty (according to information 83 | calculated from the input channelmap) channels removed 84 | - user uses this information to create the desired output channelmap, 85 | and calls SetOutputFormat to set it (if the channelmap contains channels 86 | that do not exist in the configured speaker layout, they will contain 87 | only silence unless ignoreLayout is true) 88 | */ 89 | 90 | class CPCMRemap 91 | { 92 | protected: 93 | bool m_inSet, m_outSet; 94 | enum PCMLayout m_channelLayout; 95 | unsigned int m_inChannels, m_outChannels; 96 | unsigned int m_inSampleSize; 97 | enum PCMChannels m_inMap [PCM_MAX_CH]; 98 | enum PCMChannels m_outMap[PCM_MAX_CH]; 99 | enum PCMChannels m_layoutMap[PCM_MAX_CH + 1]; 100 | 101 | bool m_ignoreLayout; 102 | bool m_useable [PCM_MAX_CH]; 103 | int m_inStride, m_outStride; 104 | struct PCMMapInfo m_lookupMap[PCM_MAX_CH + 1][PCM_MAX_CH + 1]; 105 | int m_counts[PCM_MAX_CH]; 106 | 107 | float* m_buf; 108 | int m_bufsize; 109 | float m_attenuation; 110 | float m_attenuationInc; 111 | float m_attenuationMin; //lowest attenuation value during a call of Remap(), used for the codec info 112 | float m_sampleRate; 113 | unsigned int m_holdCounter; 114 | bool m_limiterEnabled; 115 | bool m_dontnormalize; 116 | 117 | struct PCMMapInfo* ResolveChannel(enum PCMChannels channel, float level, bool ifExists, std::vector path, struct PCMMapInfo *tablePtr); 118 | void ResolveChannels(); //!< Partial BuildMap(), just enough to see which output channels are active 119 | void BuildMap(); 120 | void DumpMap(CStdString info, int unsigned channels, enum PCMChannels *channelMap); 121 | void Dispose(); 122 | CStdString PCMChannelStr(enum PCMChannels ename); 123 | CStdString PCMLayoutStr(enum PCMLayout ename); 124 | 125 | void CheckBufferSize(int size); 126 | void ProcessInput(void* data, void* out, unsigned int samples, float gain); 127 | void AddGain(float* buf, unsigned int samples, float gain); 128 | void ProcessLimiter(unsigned int samples, float gain); 129 | void ProcessOutput(void* out, unsigned int samples, float gain); 130 | 131 | public: 132 | 133 | CPCMRemap(); 134 | ~CPCMRemap(); 135 | 136 | void Reset(); 137 | enum PCMChannels *SetInputFormat (unsigned int channels, enum PCMChannels *channelMap, unsigned int sampleSize, unsigned int sampleRate, enum PCMLayout channelLayout, bool dontnormalize); 138 | void SetOutputFormat(unsigned int channels, enum PCMChannels *channelMap, bool ignoreLayout = false); 139 | #if 0 140 | void Remap(void *data, void *out, unsigned int samples, long drc); 141 | void Remap(void *data, void *out, unsigned int samples, float gain = 1.0f); 142 | bool CanRemap(); 143 | int InBytesToFrames (int bytes ); 144 | int FramesToOutBytes(int frames); 145 | int FramesToInBytes (int frames); 146 | #endif 147 | float GetCurrentAttenuation() { return m_attenuationMin; } 148 | void GetDownmixMatrix(float *downmix); 149 | }; 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /OMXAudio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * XBMC Media Center 3 | * Copyright (c) 2002 d7o3g4q and RUNTiME 4 | * Portions Copyright (c) by the authors of ffmpeg and xvid 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | */ 20 | 21 | ////////////////////////////////////////////////////////////////////// 22 | 23 | #ifndef __OPENMAXAUDIORENDER_H__ 24 | #define __OPENMAXAUDIORENDER_H__ 25 | 26 | #if _MSC_VER > 1000 27 | #pragma once 28 | #endif // _MSC_VER > 1000 29 | 30 | #include "linux/PlatformDefs.h" 31 | #include "DllAvCodec.h" 32 | #include "DllAvUtil.h" 33 | #include "utils/PCMRemap.h" 34 | #include "OMXCore.h" 35 | #include "OMXClock.h" 36 | #include "OMXStreamInfo.h" 37 | #include "BitstreamConverter.h" 38 | #include "utils/PCMRemap.h" 39 | #include "utils/SingleLock.h" 40 | 41 | #define AUDIO_BUFFER_SECONDS 3 42 | 43 | class COMXAudio 44 | { 45 | public: 46 | enum EEncoded { 47 | ENCODED_NONE = 0, 48 | ENCODED_IEC61937_AC3, 49 | ENCODED_IEC61937_EAC3, 50 | ENCODED_IEC61937_DTS, 51 | ENCODED_IEC61937_MPEG, 52 | ENCODED_IEC61937_UNKNOWN, 53 | }; 54 | 55 | unsigned int GetChunkLen(); 56 | float GetDelay(); 57 | float GetCacheTime(); 58 | float GetCacheTotal(); 59 | unsigned int GetAudioRenderingLatency(); 60 | float GetMaxLevel(double &pts); 61 | COMXAudio(); 62 | bool Initialize(const CStdString& device, int iChannels, uint64_t channelMap, 63 | COMXStreamInfo &hints, enum PCMLayout layout, unsigned int uiSamplesPerSec, unsigned int uiBitsPerSample, bool boostOnDownmix, 64 | OMXClock *clock, bool bUsePassthrough = false, bool bUseHWDecode = false, bool is_live = false, float fifo_size = 0); 65 | ~COMXAudio(); 66 | bool PortSettingsChanged(); 67 | 68 | unsigned int AddPackets(const void* data, unsigned int len); 69 | unsigned int AddPackets(const void* data, unsigned int len, double dts, double pts, unsigned int frame_size); 70 | unsigned int GetSpace(); 71 | bool Deinitialize(); 72 | 73 | void SetVolume(float nVolume); 74 | float GetVolume(); 75 | void SetMute(bool bOnOff); 76 | void SetDynamicRangeCompression(long drc); 77 | bool ApplyVolume(); 78 | void SubmitEOS(); 79 | bool IsEOS(); 80 | 81 | void Flush(); 82 | 83 | void Process(); 84 | 85 | bool SetClock(OMXClock *clock); 86 | void SetCodingType(AVCodecID codec); 87 | bool CanHWDecode(AVCodecID codec); 88 | static bool HWDecode(AVCodecID codec); 89 | 90 | void PrintChannels(OMX_AUDIO_CHANNELTYPE eChannelMapping[]); 91 | void PrintPCM(OMX_AUDIO_PARAM_PCMMODETYPE *pcm, std::string direction); 92 | void PrintDDP(OMX_AUDIO_PARAM_DDPTYPE *ddparm); 93 | void PrintDTS(OMX_AUDIO_PARAM_DTSTYPE *dtsparam); 94 | unsigned int SyncDTS(BYTE* pData, unsigned int iSize); 95 | unsigned int SyncAC3(BYTE* pData, unsigned int iSize); 96 | void UpdateAttenuation(); 97 | void BuildChannelMap(enum PCMChannels *channelMap, uint64_t layout); 98 | int BuildChannelMapCEA(enum PCMChannels *channelMap, uint64_t layout); 99 | void BuildChannelMapOMX(enum OMX_AUDIO_CHANNELTYPE *channelMap, uint64_t layout); 100 | uint64_t GetChannelLayout(enum PCMLayout layout); 101 | 102 | private: 103 | bool m_Initialized; 104 | float m_CurrentVolume; 105 | bool m_Mute; 106 | long m_drc; 107 | bool m_Passthrough; 108 | bool m_HWDecode; 109 | bool m_normalize_downmix; 110 | unsigned int m_BytesPerSec; 111 | unsigned int m_InputBytesPerSec; 112 | unsigned int m_BufferLen; 113 | unsigned int m_ChunkLen; 114 | unsigned int m_InputChannels; 115 | unsigned int m_OutputChannels; 116 | unsigned int m_BitsPerSample; 117 | float m_maxLevel; 118 | float m_amplification; 119 | float m_attenuation; 120 | float m_submitted; 121 | COMXCoreComponent *m_omx_clock; 122 | OMXClock *m_av_clock; 123 | bool m_settings_changed; 124 | bool m_setStartTime; 125 | bool m_LostSync; 126 | int m_SampleRate; 127 | OMX_AUDIO_CODINGTYPE m_eEncoding; 128 | uint8_t *m_extradata; 129 | int m_extrasize; 130 | std::string m_deviceuse; 131 | double m_last_pts; 132 | bool m_submitted_eos; 133 | bool m_failed_eos; 134 | float m_fifo_size; 135 | bool m_live; 136 | 137 | OMX_AUDIO_CHANNELTYPE m_input_channels[OMX_AUDIO_MAXCHANNELS]; 138 | OMX_AUDIO_CHANNELTYPE m_output_channels[OMX_AUDIO_MAXCHANNELS]; 139 | OMX_AUDIO_PARAM_PCMMODETYPE m_pcm_output; 140 | OMX_AUDIO_PARAM_PCMMODETYPE m_pcm_input; 141 | OMX_AUDIO_PARAM_DTSTYPE m_dtsParam; 142 | WAVEFORMATEXTENSIBLE m_wave_header; 143 | typedef struct { 144 | double pts; 145 | float level; 146 | } amplitudes_t; 147 | std::deque m_ampqueue; 148 | float m_downmix_matrix[OMX_AUDIO_MAXCHANNELS*OMX_AUDIO_MAXCHANNELS]; 149 | 150 | protected: 151 | COMXCoreComponent m_omx_render_analog; 152 | COMXCoreComponent m_omx_render_hdmi; 153 | COMXCoreComponent m_omx_splitter; 154 | COMXCoreComponent m_omx_mixer; 155 | COMXCoreComponent m_omx_decoder; 156 | COMXCoreTunel m_omx_tunnel_clock_analog; 157 | COMXCoreTunel m_omx_tunnel_clock_hdmi; 158 | COMXCoreTunel m_omx_tunnel_mixer; 159 | COMXCoreTunel m_omx_tunnel_decoder; 160 | COMXCoreTunel m_omx_tunnel_splitter_analog; 161 | COMXCoreTunel m_omx_tunnel_splitter_hdmi; 162 | DllAvUtil m_dllAvUtil; 163 | CCriticalSection m_critSection; 164 | }; 165 | #endif 166 | 167 | -------------------------------------------------------------------------------- /DllSwResample.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | * Copyright (C) 2005-2010 Team XBMC 4 | * http://www.xbmc.org 5 | * 6 | * This Program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2, or (at your option) 9 | * any later version. 10 | * 11 | * This Program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with XBMC; see the file COPYING. If not, write to 18 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 19 | * http://www.gnu.org/copyleft/gpl.html 20 | * 21 | */ 22 | 23 | #if (defined HAVE_CONFIG_H) && (!defined WIN32) 24 | #include "config.h" 25 | #endif 26 | #include "DynamicDll.h" 27 | #include "utils/log.h" 28 | 29 | extern "C" { 30 | #ifndef HAVE_MMX 31 | #define HAVE_MMX 32 | #endif 33 | #ifndef __STDC_CONSTANT_MACROS 34 | #define __STDC_CONSTANT_MACROS 35 | #endif 36 | #ifndef __GNUC__ 37 | #pragma warning(disable:4244) 38 | #endif 39 | #if (defined USE_EXTERNAL_FFMPEG) 40 | #if HAVE_LIBSWRESAMPLE_SWRESAMPLE_H 41 | #include 42 | #elif HAVE_LIBAVRESAMPLE_AVRESAMPLE_H 43 | #include 44 | #include 45 | #include 46 | #define SwrContext AVAudioResampleContext 47 | #else 48 | #error "Either libswresample or libavresample is needed!" 49 | #endif 50 | #else 51 | #include "libswresample/swresample.h" 52 | #endif 53 | } 54 | 55 | class DllSwResampleInterface 56 | { 57 | public: 58 | virtual ~DllSwResampleInterface() {} 59 | virtual struct SwrContext *swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx)=0; 60 | virtual int swr_init(struct SwrContext *s)=0; 61 | virtual void swr_free(struct SwrContext **s)=0; 62 | virtual int swr_convert(struct SwrContext *s, uint8_t **out, int out_count, const uint8_t **in , int in_count)=0; 63 | }; 64 | 65 | #if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) 66 | 67 | #if HAVE_LIBSWRESAMPLE_SWRESAMPLE_H || (defined TARGET_DARWIN) 68 | // Use direct mapping 69 | class DllSwResample : public DllDynamic, DllSwResampleInterface 70 | { 71 | public: 72 | virtual ~DllSwResample() {} 73 | 74 | // DLL faking. 75 | virtual bool ResolveExports() { return true; } 76 | virtual bool Load() { 77 | CLog::Log(LOGDEBUG, "DllAvFormat: Using libswresample system library"); 78 | return true; 79 | } 80 | virtual void Unload() {} 81 | virtual struct SwrContext *swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx) { return ::swr_alloc_set_opts(s, out_ch_layout, out_sample_fmt, out_sample_rate, in_ch_layout, in_sample_fmt, in_sample_rate, log_offset, log_ctx); } 82 | virtual int swr_init(struct SwrContext *s) { return ::swr_init(s); } 83 | virtual void swr_free(struct SwrContext **s){ return ::swr_free(s); } 84 | virtual int swr_convert(struct SwrContext *s, uint8_t **out, int out_count, const uint8_t **in , int in_count){ return ::swr_convert(s, out, out_count, in, in_count); } 85 | }; 86 | #else 87 | // Wrap the same API through libavresample. 88 | class DllSwResample : public DllDynamic, DllSwResampleInterface 89 | { 90 | public: 91 | virtual ~DllSwResample() {} 92 | 93 | // DLL faking. 94 | virtual bool ResolveExports() { return true; } 95 | virtual bool Load() { 96 | CLog::Log(LOGDEBUG, "DllAvFormat: Using libavresample system library"); 97 | return true; 98 | } 99 | virtual void Unload() {} 100 | virtual struct SwrContext *swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx) { 101 | AVAudioResampleContext *ret = ::avresample_alloc_context(); 102 | av_opt_set_int(ret, "out_channel_layout", out_ch_layout , 0); 103 | av_opt_set_int(ret, "out_sample_fmt" , out_sample_fmt , 0); 104 | av_opt_set_int(ret, "out_sample_rate" , out_sample_rate, 0); 105 | av_opt_set_int(ret, "in_channel_layout" , in_ch_layout , 0); 106 | av_opt_set_int(ret, "in_sample_fmt" , in_sample_fmt , 0); 107 | av_opt_set_int(ret, "in_sample_rate" , in_sample_rate , 0); 108 | return ret; 109 | } 110 | virtual int swr_init(struct SwrContext *s) { return ::avresample_open(s); } 111 | virtual void swr_free(struct SwrContext **s){ ::avresample_close(*s); *s = NULL; } 112 | virtual int swr_convert(struct SwrContext *s, uint8_t **out, int out_count, const uint8_t **in , int in_count){ return ::avresample_convert(s, (void**)out, 0, out_count, (void**)in, 0,in_count); } 113 | }; 114 | #endif 115 | 116 | #else 117 | 118 | class DllSwResample : public DllDynamic, DllSwResampleInterface 119 | { 120 | DECLARE_DLL_WRAPPER(DllSwResample, DLL_PATH_LIBSWRESAMPLE) 121 | 122 | LOAD_SYMBOLS() 123 | 124 | DEFINE_METHOD9(SwrContext*, swr_alloc_set_opts, (struct SwrContext *p1, int64_t p2, enum AVSampleFormat p3, int p4, int64_t p5, enum AVSampleFormat p6, int p7, int p8, void * p9)); 125 | DEFINE_METHOD1(int, swr_init, (struct SwrContext *p1)) 126 | DEFINE_METHOD1(void, swr_free, (struct SwrContext **p1)) 127 | DEFINE_METHOD5(int, swr_convert, (struct SwrContext *p1, uint8_t **p2, int p3, const uint8_t **p4, int p5)) 128 | 129 | BEGIN_METHOD_RESOLVE() 130 | RESOLVE_METHOD(swr_alloc_set_opts) 131 | RESOLVE_METHOD(swr_init) 132 | RESOLVE_METHOD(swr_free) 133 | RESOLVE_METHOD(swr_convert) 134 | END_METHOD_RESOLVE() 135 | 136 | /* dependencies of libavformat */ 137 | DllAvUtil m_dllAvUtil; 138 | 139 | public: 140 | 141 | virtual bool Load() 142 | { 143 | if (!m_dllAvUtil.Load()) 144 | return false; 145 | return DllDynamic::Load(); 146 | } 147 | }; 148 | 149 | #endif 150 | -------------------------------------------------------------------------------- /BitstreamConverter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #ifndef _BITSTREAMCONVERTER_H_ 23 | #define _BITSTREAMCONVERTER_H_ 24 | 25 | #include 26 | #include "DllAvUtil.h" 27 | #include "DllAvFormat.h" 28 | #include "DllAvFilter.h" 29 | #include "DllAvCodec.h" 30 | 31 | typedef struct { 32 | uint8_t *buffer, *start; 33 | int offbits, length, oflow; 34 | } bits_reader_t; 35 | 36 | //////////////////////////////////////////////////////////////////////////////////////////// 37 | // TODO: refactor this so as not to need these ffmpeg routines. 38 | // These are not exposed in ffmpeg's API so we dupe them here. 39 | // AVC helper functions for muxers, 40 | // * Copyright (c) 2006 Baptiste Coudurier 41 | // This is part of FFmpeg 42 | // * License as published by the Free Software Foundation; either 43 | // * version 2.1 of the License, or (at your option) any later version. 44 | #define OMX_RB16(x) \ 45 | ((((const uint8_t*)(x))[0] << 8) | \ 46 | ((const uint8_t*)(x)) [1]) 47 | 48 | #define OMX_RB24(x) \ 49 | ((((const uint8_t*)(x))[0] << 16) | \ 50 | (((const uint8_t*)(x))[1] << 8) | \ 51 | ((const uint8_t*)(x))[2]) 52 | 53 | #define OMX_RB32(x) \ 54 | ((((const uint8_t*)(x))[0] << 24) | \ 55 | (((const uint8_t*)(x))[1] << 16) | \ 56 | (((const uint8_t*)(x))[2] << 8) | \ 57 | ((const uint8_t*)(x))[3]) 58 | 59 | #define OMX_WB32(p, d) { \ 60 | ((uint8_t*)(p))[3] = (d); \ 61 | ((uint8_t*)(p))[2] = (d) >> 8; \ 62 | ((uint8_t*)(p))[1] = (d) >> 16; \ 63 | ((uint8_t*)(p))[0] = (d) >> 24; } 64 | 65 | typedef struct 66 | { 67 | const uint8_t *data; 68 | const uint8_t *end; 69 | int head; 70 | uint64_t cache; 71 | } nal_bitstream; 72 | 73 | typedef struct 74 | { 75 | int profile_idc; 76 | int level_idc; 77 | int sps_id; 78 | 79 | int chroma_format_idc; 80 | int separate_colour_plane_flag; 81 | int bit_depth_luma_minus8; 82 | int bit_depth_chroma_minus8; 83 | int qpprime_y_zero_transform_bypass_flag; 84 | int seq_scaling_matrix_present_flag; 85 | 86 | int log2_max_frame_num_minus4; 87 | int pic_order_cnt_type; 88 | int log2_max_pic_order_cnt_lsb_minus4; 89 | 90 | int max_num_ref_frames; 91 | int gaps_in_frame_num_value_allowed_flag; 92 | int pic_width_in_mbs_minus1; 93 | int pic_height_in_map_units_minus1; 94 | 95 | int frame_mbs_only_flag; 96 | int mb_adaptive_frame_field_flag; 97 | 98 | int direct_8x8_inference_flag; 99 | 100 | int frame_cropping_flag; 101 | int frame_crop_left_offset; 102 | int frame_crop_right_offset; 103 | int frame_crop_top_offset; 104 | int frame_crop_bottom_offset; 105 | } sps_info_struct; 106 | 107 | class CBitstreamConverter 108 | { 109 | public: 110 | CBitstreamConverter(); 111 | ~CBitstreamConverter(); 112 | // Required overrides 113 | static void bits_reader_set( bits_reader_t *br, uint8_t *buf, int len ); 114 | static uint32_t read_bits( bits_reader_t *br, int nbits ); 115 | static void skip_bits( bits_reader_t *br, int nbits ); 116 | static uint32_t get_bits( bits_reader_t *br, int nbits ); 117 | 118 | bool Open(enum AVCodecID codec, uint8_t *in_extradata, int in_extrasize, bool to_annexb); 119 | void Close(void); 120 | bool NeedConvert(void) { return m_convert_bitstream; }; 121 | bool Convert(uint8_t *pData, int iSize); 122 | uint8_t *GetConvertBuffer(void); 123 | int GetConvertSize(); 124 | uint8_t *GetExtraData(void); 125 | int GetExtraSize(); 126 | void parseh264_sps(uint8_t *sps, uint32_t sps_size, bool *interlaced, int32_t *max_ref_frames); 127 | protected: 128 | // bytestream (Annex B) to bistream conversion support. 129 | void nal_bs_init(nal_bitstream *bs, const uint8_t *data, size_t size); 130 | uint32_t nal_bs_read(nal_bitstream *bs, int n); 131 | bool nal_bs_eos(nal_bitstream *bs); 132 | int nal_bs_read_ue(nal_bitstream *bs); 133 | const uint8_t *avc_find_startcode_internal(const uint8_t *p, const uint8_t *end); 134 | const uint8_t *avc_find_startcode(const uint8_t *p, const uint8_t *end); 135 | const int avc_parse_nal_units(AVIOContext *pb, const uint8_t *buf_in, int size); 136 | const int avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size); 137 | const int isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len); 138 | // bitstream to bytestream (Annex B) conversion support. 139 | bool BitstreamConvertInit(void *in_extradata, int in_extrasize); 140 | bool BitstreamConvert(uint8_t* pData, int iSize, uint8_t **poutbuf, int *poutbuf_size); 141 | void BitstreamAllocAndCopy( uint8_t **poutbuf, int *poutbuf_size, 142 | const uint8_t *sps_pps, uint32_t sps_pps_size, const uint8_t *in, uint32_t in_size); 143 | 144 | typedef struct omx_bitstream_ctx { 145 | uint8_t length_size; 146 | uint8_t first_idr; 147 | uint8_t *sps_pps_data; 148 | uint32_t size; 149 | } omx_bitstream_ctx; 150 | 151 | uint8_t *m_convertBuffer; 152 | int m_convertSize; 153 | uint8_t *m_inputBuffer; 154 | int m_inputSize; 155 | 156 | uint32_t m_sps_pps_size; 157 | omx_bitstream_ctx m_sps_pps_context; 158 | bool m_convert_bitstream; 159 | bool m_to_annexb; 160 | 161 | uint8_t *m_extradata; 162 | int m_extrasize; 163 | bool m_convert_3byteTo4byteNALSize; 164 | bool m_convert_bytestream; 165 | DllAvUtil *m_dllAvUtil; 166 | DllAvFormat *m_dllAvFormat; 167 | AVCodecID m_codec; 168 | }; 169 | 170 | #endif 171 | -------------------------------------------------------------------------------- /KeyConfig.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "KeyConfig.h" 7 | 8 | using namespace std; 9 | 10 | /* Converts the action string from the config file into 11 | * the corresponding enum value 12 | */ 13 | int convertStringToAction(string str_action) 14 | { 15 | if(str_action == "DECREASE_SPEED") 16 | return KeyConfig::ACTION_DECREASE_SPEED; 17 | if(str_action == "INCREASE_SPEED") 18 | return KeyConfig::ACTION_INCREASE_SPEED; 19 | if(str_action == "REWIND") 20 | return KeyConfig::ACTION_REWIND; 21 | if(str_action == "FAST_FORWARD") 22 | return KeyConfig::ACTION_FAST_FORWARD; 23 | if(str_action == "SHOW_INFO") 24 | return KeyConfig::ACTION_SHOW_INFO; 25 | if(str_action == "PREVIOUS_AUDIO") 26 | return KeyConfig::ACTION_PREVIOUS_AUDIO; 27 | if(str_action == "NEXT_AUDIO") 28 | return KeyConfig::ACTION_NEXT_AUDIO; 29 | if(str_action == "PREVIOUS_CHAPTER") 30 | return KeyConfig::ACTION_PREVIOUS_CHAPTER; 31 | if(str_action == "NEXT_CHAPTER") 32 | return KeyConfig::ACTION_NEXT_CHAPTER; 33 | if(str_action == "PREVIOUS_SUBTITLE") 34 | return KeyConfig::ACTION_PREVIOUS_SUBTITLE; 35 | if(str_action == "NEXT_SUBTITLE") 36 | return KeyConfig::ACTION_NEXT_SUBTITLE; 37 | if(str_action == "TOGGLE_SUBTITLE") 38 | return KeyConfig::ACTION_TOGGLE_SUBTITLE; 39 | if(str_action == "DECREASE_SUBTITLE_DELAY") 40 | return KeyConfig::ACTION_DECREASE_SUBTITLE_DELAY; 41 | if(str_action == "INCREASE_SUBTITLE_DELAY") 42 | return KeyConfig::ACTION_INCREASE_SUBTITLE_DELAY; 43 | if(str_action == "EXIT") 44 | return KeyConfig::ACTION_EXIT; 45 | if(str_action == "PAUSE") 46 | return KeyConfig::ACTION_PAUSE; 47 | if(str_action == "DECREASE_VOLUME") 48 | return KeyConfig::ACTION_DECREASE_VOLUME; 49 | if(str_action == "INCREASE_VOLUME") 50 | return KeyConfig::ACTION_INCREASE_VOLUME; 51 | if(str_action == "SEEK_BACK_SMALL") 52 | return KeyConfig::ACTION_SEEK_BACK_SMALL; 53 | if(str_action == "SEEK_FORWARD_SMALL") 54 | return KeyConfig::ACTION_SEEK_FORWARD_SMALL; 55 | if(str_action == "SEEK_BACK_LARGE") 56 | return KeyConfig::ACTION_SEEK_BACK_LARGE; 57 | if(str_action == "SEEK_FORWARD_LARGE") 58 | return KeyConfig::ACTION_SEEK_FORWARD_LARGE; 59 | if(str_action == "STEP") 60 | return KeyConfig::ACTION_STEP; 61 | 62 | return -1; 63 | } 64 | /* Grabs the substring prior to the ':', this is the Action */ 65 | string getActionFromString(string line) 66 | { 67 | string action; 68 | unsigned int colonIndex = line.find(":"); 69 | if(colonIndex == string::npos) 70 | return ""; 71 | 72 | action = line.substr(0,colonIndex); 73 | 74 | return action; 75 | } 76 | 77 | /* Grabs the substring after the ':', this is the Key */ 78 | string getKeyFromString(string line) 79 | { 80 | string key; 81 | unsigned int colonIndex = line.find(":"); 82 | if(colonIndex == string::npos) 83 | return ""; 84 | 85 | key = line.substr(colonIndex+1); 86 | 87 | return key; 88 | } 89 | 90 | /* Returns a keymap consisting of the default 91 | * keybinds specified with the -k option 92 | */ 93 | map KeyConfig::buildDefaultKeymap() 94 | { 95 | map keymap; 96 | 97 | keymap['1'] = ACTION_DECREASE_SPEED; 98 | keymap['2'] = ACTION_INCREASE_SPEED; 99 | keymap['<'] = ACTION_REWIND; 100 | keymap[','] = ACTION_REWIND; 101 | keymap['>'] = ACTION_FAST_FORWARD; 102 | keymap['.'] = ACTION_FAST_FORWARD; 103 | keymap['z'] = ACTION_SHOW_INFO; 104 | keymap['j'] = ACTION_PREVIOUS_AUDIO; 105 | keymap['k'] = ACTION_NEXT_AUDIO; 106 | keymap['i'] = ACTION_PREVIOUS_CHAPTER; 107 | keymap['o'] = ACTION_NEXT_CHAPTER; 108 | keymap['n'] = ACTION_PREVIOUS_SUBTITLE; 109 | keymap['m'] = ACTION_NEXT_SUBTITLE; 110 | keymap['s'] = ACTION_TOGGLE_SUBTITLE; 111 | keymap['d'] = ACTION_DECREASE_SUBTITLE_DELAY; 112 | keymap['f'] = ACTION_INCREASE_SUBTITLE_DELAY; 113 | keymap['q'] = ACTION_EXIT; 114 | keymap[KEY_ESC] = ACTION_EXIT; 115 | keymap['p'] = ACTION_PAUSE; 116 | keymap[' '] = ACTION_PAUSE; 117 | keymap['-'] = ACTION_DECREASE_VOLUME; 118 | keymap['+'] = ACTION_INCREASE_VOLUME; 119 | keymap['='] = ACTION_INCREASE_VOLUME; 120 | keymap[KEY_LEFT] = ACTION_SEEK_BACK_SMALL; 121 | keymap[KEY_RIGHT] = ACTION_SEEK_FORWARD_SMALL; 122 | keymap[KEY_DOWN] = ACTION_SEEK_BACK_LARGE; 123 | keymap[KEY_UP] = ACTION_SEEK_FORWARD_LARGE; 124 | // keymap[KEY_DOWN] = ACTION_BLUR; 125 | // keymap[KEY_UP] = ACTION_SHOW; 126 | keymap['v'] = ACTION_STEP; 127 | 128 | return keymap; 129 | } 130 | 131 | /* Parses the supplied config file and turns it into a map object. 132 | * NOTE: Does not work with certain filepath shortcuts (e.g. ~ as user's home) 133 | */ 134 | map KeyConfig::parseConfigFile(string filepath) 135 | { 136 | ifstream config_file(filepath.c_str()); 137 | map keymap; 138 | string line; 139 | 140 | while(getline(config_file, line)) 141 | { 142 | string str_action = getActionFromString(line); 143 | string key = getKeyFromString(line); 144 | 145 | if(str_action != "" && key != "" && str_action[0] != '#') 146 | { 147 | int key_action = convertStringToAction(str_action); 148 | if(key.substr(0,4) == "left") 149 | { 150 | keymap[KEY_LEFT] = key_action; 151 | } 152 | else if(key.substr(0,5) == "right") 153 | { 154 | keymap[KEY_RIGHT] = key_action; 155 | } 156 | else if(key.substr(0,2) == "up") 157 | { 158 | keymap[KEY_UP] = key_action; 159 | } 160 | else if(key.substr(0,4) == "down") 161 | { 162 | keymap[KEY_DOWN] = key_action; 163 | } 164 | else if(key.substr(0,3) == "esc") 165 | { 166 | keymap[KEY_ESC] = key_action; 167 | } 168 | else if(key.substr(0,3) == "hex") 169 | { 170 | const char *hex = key.substr(4).c_str(); 171 | if (hex) 172 | keymap[strtoul(hex,0,0)] = key_action; 173 | } 174 | else keymap[key[0]] = key_action; 175 | } 176 | } 177 | return keymap; 178 | } 179 | -------------------------------------------------------------------------------- /OMXReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2008 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #ifndef _OMX_READER_H_ 23 | #define _OMX_READER_H_ 24 | 25 | #include "DllAvUtil.h" 26 | #include "DllAvFormat.h" 27 | #include "DllAvFilter.h" 28 | #include "DllAvCodec.h" 29 | #include "OMXStreamInfo.h" 30 | #include "OMXThread.h" 31 | #include 32 | 33 | #include "OMXStreamInfo.h" 34 | 35 | #include "File.h" 36 | 37 | #include 38 | #include 39 | 40 | using namespace XFILE; 41 | using namespace std; 42 | 43 | #define MAX_OMX_CHAPTERS 64 44 | 45 | #define MAX_OMX_STREAMS 100 46 | 47 | #ifndef FFMPEG_FILE_BUFFER_SIZE 48 | #define FFMPEG_FILE_BUFFER_SIZE 32768 // default reading size for ffmpeg 49 | #endif 50 | #ifndef MAX_STREAMS 51 | #define MAX_STREAMS 100 52 | #endif 53 | 54 | typedef struct OMXChapter 55 | { 56 | std::string name; 57 | int64_t seekto_ms; 58 | double ts; 59 | } OMXChapter; 60 | 61 | class OMXReader; 62 | 63 | typedef struct OMXPacket 64 | { 65 | double pts; // pts in DVD_TIME_BASE 66 | double dts; // dts in DVD_TIME_BASE 67 | double now; // dts in DVD_TIME_BASE 68 | double duration; // duration in DVD_TIME_BASE if available 69 | int size; 70 | uint8_t *data; 71 | int stream_index; 72 | COMXStreamInfo hints; 73 | enum AVMediaType codec_type; 74 | } OMXPacket; 75 | 76 | enum OMXStreamType 77 | { 78 | OMXSTREAM_NONE = 0, 79 | OMXSTREAM_AUDIO = 1, 80 | OMXSTREAM_VIDEO = 2, 81 | OMXSTREAM_SUBTITLE = 3 82 | }; 83 | 84 | typedef struct OMXStream 85 | { 86 | char language[4]; 87 | std::string name; 88 | std::string codec_name; 89 | AVStream *stream; 90 | OMXStreamType type; 91 | int id; 92 | void *extradata; 93 | unsigned int extrasize; 94 | unsigned int index; 95 | COMXStreamInfo hints; 96 | } OMXStream; 97 | 98 | class OMXReader 99 | { 100 | protected: 101 | int m_video_index; 102 | int m_audio_index; 103 | int m_subtitle_index; 104 | int m_video_count; 105 | int m_audio_count; 106 | int m_subtitle_count; 107 | DllAvUtil m_dllAvUtil; 108 | DllAvCodec m_dllAvCodec; 109 | DllAvFormat m_dllAvFormat; 110 | bool m_open; 111 | std::string m_filename; 112 | bool m_bMatroska; 113 | bool m_bAVI; 114 | XFILE::CFile *m_pFile; 115 | AVFormatContext *m_pFormatContext; 116 | AVIOContext *m_ioContext; 117 | bool m_eof; 118 | OMXChapter m_chapters[MAX_OMX_CHAPTERS]; 119 | OMXStream m_streams[MAX_STREAMS]; 120 | int m_chapter_count; 121 | double m_iCurrentPts; 122 | int m_speed; 123 | unsigned int m_program; 124 | pthread_mutex_t m_lock; 125 | void Lock(); 126 | void UnLock(); 127 | bool SetActiveStreamInternal(OMXStreamType type, unsigned int index); 128 | bool m_seek; 129 | private: 130 | public: 131 | OMXReader(); 132 | ~OMXReader(); 133 | bool Open(std::string filename, bool dump_format, bool live = false, float timeout = 0.0f); 134 | void ClearStreams(); 135 | bool Close(); 136 | //void FlushRead(); 137 | bool SeekTime(int time, bool backwords, double *startpts); 138 | AVMediaType PacketType(OMXPacket *pkt); 139 | OMXPacket *Read(); 140 | void Process(); 141 | bool GetStreams(); 142 | int64_t GetDuration(); 143 | void AddStream(int id); 144 | bool IsActive(int stream_index); 145 | bool IsActive(OMXStreamType type, int stream_index); 146 | bool GetHints(AVStream *stream, COMXStreamInfo *hints); 147 | bool GetHints(OMXStreamType type, unsigned int index, COMXStreamInfo &hints); 148 | bool GetHints(OMXStreamType type, COMXStreamInfo &hints); 149 | bool IsEof(); 150 | int AudioStreamCount() { return m_audio_count; }; 151 | int VideoStreamCount() { return m_video_count; }; 152 | int SubtitleStreamCount() { return m_subtitle_count; }; 153 | bool SetActiveStream(OMXStreamType type, unsigned int index); 154 | int GetChapterCount() { return m_chapter_count; }; 155 | OMXChapter GetChapter(unsigned int chapter) { return m_chapters[(chapter > MAX_OMX_CHAPTERS) ? MAX_OMX_CHAPTERS : chapter]; }; 156 | static void FreePacket(OMXPacket *pkt); 157 | static OMXPacket *AllocPacket(int size); 158 | void SetSpeed(int iSpeed); 159 | void UpdateCurrentPTS(); 160 | double ConvertTimestamp(int64_t pts, int den, int num); 161 | int GetChapter(); 162 | void GetChapterName(std::string& strChapterName); 163 | bool SeekChapter(int chapter, double* startpts); 164 | int GetAudioIndex() { return (m_audio_index >= 0) ? m_streams[m_audio_index].index : -1; }; 165 | int GetSubtitleIndex() { return (m_subtitle_index >= 0) ? m_streams[m_subtitle_index].index : -1; }; 166 | int GetVideoIndex() { return (m_video_index >= 0) ? m_streams[m_video_index].index : -1; }; 167 | 168 | int GetRelativeIndex(size_t index) 169 | { 170 | assert(index < MAX_STREAMS); 171 | return m_streams[index].index; 172 | } 173 | 174 | int GetStreamLength(); 175 | static double NormalizeFrameduration(double frameduration); 176 | bool IsMatroska() { return m_bMatroska; }; 177 | std::string GetCodecName(OMXStreamType type); 178 | std::string GetCodecName(OMXStreamType type, unsigned int index); 179 | std::string GetStreamCodecName(AVStream *stream); 180 | std::string GetStreamLanguage(OMXStreamType type, unsigned int index); 181 | std::string GetStreamName(OMXStreamType type, unsigned int index); 182 | std::string GetStreamType(OMXStreamType type, unsigned int index); 183 | bool CanSeek(); 184 | }; 185 | #endif 186 | -------------------------------------------------------------------------------- /SubtitleRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Author: Torarin Hals Bakke (2012) 4 | 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | 29 | #include 30 | #include 31 | #include 32 | #include FT_FREETYPE_H 33 | #include FT_STROKER_H 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | class TagTracker { 40 | public: 41 | TagTracker() : italic_(), state_(), closing_() {}; 42 | 43 | void put(char32_t cp) { 44 | if (state_ == '>') 45 | state_ = 0; 46 | 47 | switch (cp) { 48 | case '<': 49 | state_ = '<'; 50 | closing_ = false; 51 | break; 52 | case '/': 53 | if (state_ == '<') 54 | closing_ = true; 55 | break; 56 | case 'i': 57 | if (state_) 58 | state_ = 'i'; 59 | break; 60 | case '>': 61 | if (state_) { 62 | if (state_ == 'i') 63 | italic_ = !closing_; 64 | state_ = '>'; 65 | } 66 | break; 67 | } 68 | } 69 | 70 | bool italic() { 71 | return italic_; 72 | } 73 | 74 | bool in_tag() { 75 | return state_; 76 | } 77 | 78 | private: 79 | bool italic_; 80 | char state_; 81 | bool closing_; 82 | }; 83 | 84 | class SubtitleRenderer { 85 | public: 86 | SubtitleRenderer(const SubtitleRenderer&) = delete; 87 | SubtitleRenderer& operator=(const SubtitleRenderer&) = delete; 88 | SubtitleRenderer(int level, 89 | const std::string& font_path, 90 | const std::string& italic_font_path, 91 | float font_size, 92 | float margin_left, 93 | float margin_bottom, 94 | bool centered, 95 | unsigned int white_level, 96 | unsigned int box_opacity, 97 | unsigned int lines); 98 | ~SubtitleRenderer() BOOST_NOEXCEPT; 99 | 100 | void prepare(const std::vector& text_lines) BOOST_NOEXCEPT; 101 | 102 | void unprepare() BOOST_NOEXCEPT { 103 | prepared_ = false; 104 | } 105 | 106 | void show_next() BOOST_NOEXCEPT { 107 | if (prepared_) { 108 | // puts("Expensive show_next!"); 109 | draw(); 110 | } 111 | swap_buffers(); 112 | } 113 | 114 | void hide() BOOST_NOEXCEPT { 115 | clear(); 116 | swap_buffers(); 117 | if (prepared_) 118 | draw(); 119 | } 120 | 121 | private: 122 | struct InternalChar { 123 | InternalChar() = default; 124 | InternalChar(char32_t codepoint, bool italic) { 125 | val = codepoint | (static_cast(italic) << 31); 126 | } 127 | 128 | bool operator ==(const InternalChar& other) const { 129 | return val == other.val; 130 | } 131 | 132 | char32_t codepoint() const { return val & 0x7FFFFFFF; } 133 | bool italic() const { return val >> 31; } 134 | 135 | char32_t val; 136 | }; 137 | 138 | struct InternalCharHash { 139 | size_t operator()(InternalChar ch) const noexcept { 140 | return static_cast(ch.val); 141 | } 142 | }; 143 | 144 | struct InternalGlyph { 145 | int advance; 146 | }; 147 | 148 | static void draw_text(VGFont font, 149 | const std::vector& text, 150 | int x, int y, 151 | unsigned int lightness); 152 | 153 | void destroy(); 154 | void initialize_fonts(const std::string& font_name, 155 | const std::string& italic_font_path, 156 | unsigned int font_size); 157 | void destroy_fonts(); 158 | void initialize_vg(); 159 | void destroy_vg(); 160 | void initialize_window(int layer, 161 | unsigned int x, 162 | unsigned int y, 163 | unsigned int width, 164 | unsigned int height); 165 | void destroy_window(); 166 | void clear() BOOST_NOEXCEPT; 167 | void draw() BOOST_NOEXCEPT; 168 | void swap_buffers() BOOST_NOEXCEPT; 169 | void prepare_glyphs(const std::vector& text); 170 | void load_glyph(InternalChar ch); 171 | int get_text_width(const std::vector& text); 172 | std::vector get_internal_chars(const std::string& str, 173 | TagTracker& tag_tracker); 174 | 175 | bool prepared_; 176 | DISPMANX_ELEMENT_HANDLE_T dispman_element_; 177 | DISPMANX_DISPLAY_HANDLE_T dispman_display_; 178 | EGLDisplay display_; 179 | EGLContext context_; 180 | EGLSurface surface_; 181 | VGFont vg_font_; 182 | VGFont vg_font_border_; 183 | FT_Library ft_library_; 184 | FT_Face ft_face_; 185 | FT_Face ft_face_italic_; 186 | FT_Stroker ft_stroker_; 187 | std::unordered_map glyphs_; 188 | std::vector> internal_lines_; 189 | std::vector> line_positions_; 190 | std::vector line_widths_; 191 | int line_height_; 192 | int box_offset_; 193 | int box_h_padding_; 194 | int margin_left_; 195 | int margin_bottom_; 196 | int buffer_width_; 197 | int buffer_height_; 198 | bool centered_; 199 | unsigned int white_level_; 200 | unsigned int box_opacity_; 201 | }; 202 | -------------------------------------------------------------------------------- /utils/log.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2008 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #include "system.h" 23 | #include "log.h" 24 | #include "stdio_utf8.h" 25 | #include "stat_utf8.h" 26 | #include "utils/StdString.h" 27 | 28 | static FILE* m_file = NULL; 29 | static int m_repeatCount = 0; 30 | static int m_repeatLogLevel = -1; 31 | static std::string m_repeatLine = ""; 32 | static int m_logLevel = LOG_LEVEL_NONE; 33 | 34 | static pthread_mutex_t m_log_mutex; 35 | 36 | static char levelNames[][8] = 37 | {"DEBUG", "INFO", "NOTICE", "WARNING", "ERROR", "SEVERE", "FATAL", "NONE"}; 38 | 39 | CLog::CLog() 40 | {} 41 | 42 | CLog::~CLog() 43 | {} 44 | 45 | void CLog::Close() 46 | { 47 | if (m_file) 48 | { 49 | fclose(m_file); 50 | m_file = NULL; 51 | } 52 | m_repeatLine.clear(); 53 | pthread_mutex_destroy(&m_log_mutex); 54 | } 55 | 56 | void CLog::Log(int loglevel, const char *format, ... ) 57 | { 58 | pthread_mutex_lock(&m_log_mutex); 59 | 60 | static const char* prefixFormat = "%02.2d:%02.2d:%02.2d T:%" PRIu64 " %7s: "; 61 | #if !(defined(_DEBUG) || defined(PROFILE)) 62 | if (m_logLevel > LOG_LEVEL_NORMAL || 63 | (m_logLevel > LOG_LEVEL_NONE && loglevel >= LOGNOTICE)) 64 | #endif 65 | { 66 | if (!m_file) 67 | { 68 | pthread_mutex_unlock(&m_log_mutex); 69 | return; 70 | } 71 | 72 | struct timeval now; 73 | gettimeofday(&now, NULL); 74 | SYSTEMTIME time; 75 | time.wHour=(now.tv_sec/3600) % 24; 76 | time.wMinute=(now.tv_sec/60) % 60; 77 | time.wSecond=now.tv_sec % 60; 78 | uint64_t stamp = now.tv_usec + now.tv_sec * 1000000; 79 | CStdString strPrefix, strData; 80 | 81 | strData.reserve(16384); 82 | va_list va; 83 | va_start(va, format); 84 | strData.FormatV(format,va); 85 | va_end(va); 86 | 87 | if (m_repeatLogLevel == loglevel && m_repeatLine == strData) 88 | { 89 | m_repeatCount++; 90 | pthread_mutex_unlock(&m_log_mutex); 91 | return; 92 | } 93 | else if (m_repeatCount) 94 | { 95 | CStdString strData2; 96 | strPrefix.Format(prefixFormat, time.wHour, time.wMinute, time.wSecond, stamp, levelNames[m_repeatLogLevel]); 97 | 98 | strData2.Format("Previous line repeats %d times." LINE_ENDING, m_repeatCount); 99 | fputs(strPrefix.c_str(), m_file); 100 | fputs(strData2.c_str(), m_file); 101 | OutputDebugString(strData2); 102 | m_repeatCount = 0; 103 | } 104 | 105 | m_repeatLine = strData; 106 | m_repeatLogLevel = loglevel; 107 | 108 | unsigned int length = 0; 109 | while ( length != strData.length() ) 110 | { 111 | length = strData.length(); 112 | strData.TrimRight(" "); 113 | strData.TrimRight('\n'); 114 | strData.TrimRight("\r"); 115 | } 116 | 117 | if (!length) 118 | { 119 | pthread_mutex_unlock(&m_log_mutex); 120 | return; 121 | } 122 | 123 | OutputDebugString(strData); 124 | 125 | /* fixup newline alignment, number of spaces should equal prefix length */ 126 | strData.Replace("\n", LINE_ENDING" "); 127 | strData += LINE_ENDING; 128 | 129 | strPrefix.Format(prefixFormat, time.wHour, time.wMinute, time.wSecond, stamp, levelNames[loglevel]); 130 | 131 | fputs(strPrefix.c_str(), m_file); 132 | fputs(strData.c_str(), m_file); 133 | //fputs(strPrefix.c_str(), stdout); 134 | //fputs(strData.c_str(), stdout); 135 | fflush(m_file); 136 | } 137 | 138 | pthread_mutex_unlock(&m_log_mutex); 139 | } 140 | 141 | bool CLog::Init(const char* path) 142 | { 143 | pthread_mutex_init(&m_log_mutex, NULL); 144 | if (m_logLevel > LOG_LEVEL_NONE) { 145 | if (!m_file) 146 | { 147 | CStdString strLogFile, strLogFileOld; 148 | 149 | strLogFile.Format("%s/omxplayer.log", path); 150 | strLogFileOld.Format("%s/omxplayer.old.log", path); 151 | 152 | struct stat info; 153 | if (stat(strLogFileOld.c_str(),&info) == 0 && 154 | remove(strLogFileOld.c_str()) != 0) 155 | return false; 156 | if (stat(strLogFile.c_str(),&info) == 0 && 157 | rename(strLogFile.c_str(),strLogFileOld.c_str()) != 0) 158 | return false; 159 | 160 | m_file = fopen(strLogFile.c_str(),"wb"); 161 | } 162 | 163 | if (m_file) 164 | { 165 | unsigned char BOM[3] = {0xEF, 0xBB, 0xBF}; 166 | fwrite(BOM, sizeof(BOM), 1, m_file); 167 | } 168 | } 169 | return m_file != NULL; 170 | } 171 | 172 | void CLog::MemDump(char *pData, int length) 173 | { 174 | if (m_logLevel > LOG_LEVEL_NONE) { 175 | Log(LOGDEBUG, "MEM_DUMP: Dumping from %p", pData); 176 | for (int i = 0; i < length; i+=16) 177 | { 178 | CStdString strLine; 179 | strLine.Format("MEM_DUMP: %04x ", i); 180 | char *alpha = pData; 181 | for (int k=0; k < 4 && i + 4*k < length; k++) 182 | { 183 | for (int j=0; j < 4 && i + 4*k + j < length; j++) 184 | { 185 | CStdString strFormat; 186 | strFormat.Format(" %02x", *pData++); 187 | strLine += strFormat; 188 | } 189 | strLine += " "; 190 | } 191 | // pad with spaces 192 | while (strLine.size() < 13*4 + 16) 193 | strLine += " "; 194 | for (int j=0; j < 16 && i + j < length; j++) 195 | { 196 | if (*alpha > 31) 197 | strLine += *alpha; 198 | else 199 | strLine += '.'; 200 | alpha++; 201 | } 202 | Log(LOGDEBUG, "%s", strLine.c_str()); 203 | } 204 | } 205 | } 206 | 207 | void CLog::SetLogLevel(int level) 208 | { 209 | if(m_logLevel > LOG_LEVEL_NONE) 210 | CLog::Log(LOGNOTICE, "Log level changed to %d", m_logLevel); 211 | m_logLevel = level; 212 | } 213 | 214 | int CLog::GetLogLevel() 215 | { 216 | return m_logLevel; 217 | } 218 | 219 | void CLog::OutputDebugString(const std::string& line) 220 | { 221 | #if defined(_DEBUG) || defined(PROFILE) 222 | if(m_logLevel > LOG_LEVEL_NONE) { 223 | ::OutputDebugString(line.c_str()); 224 | ::OutputDebugString("\n"); 225 | } 226 | #endif 227 | } 228 | -------------------------------------------------------------------------------- /utils/RegExp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2008 Team XBMC 3 | * http://www.xbmc.org 4 | * 5 | * This Program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2, or (at your option) 8 | * any later version. 9 | * 10 | * This Program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with XBMC; see the file COPYING. If not, write to 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * http://www.gnu.org/copyleft/gpl.html 19 | * 20 | */ 21 | 22 | #include 23 | #include 24 | #include "RegExp.h" 25 | #include "StdString.h" 26 | #include "log.h" 27 | 28 | using namespace PCRE; 29 | 30 | CRegExp::CRegExp(bool caseless) 31 | { 32 | m_re = NULL; 33 | m_iOptions = PCRE_DOTALL; 34 | if(caseless) 35 | m_iOptions |= PCRE_CASELESS; 36 | 37 | m_bMatched = false; 38 | m_iMatchCount = 0; 39 | } 40 | 41 | CRegExp::CRegExp(const CRegExp& re) 42 | { 43 | m_re = NULL; 44 | m_iOptions = re.m_iOptions; 45 | *this = re; 46 | } 47 | 48 | const CRegExp& CRegExp::operator=(const CRegExp& re) 49 | { 50 | size_t size; 51 | Cleanup(); 52 | m_pattern = re.m_pattern; 53 | if (re.m_re) 54 | { 55 | if (pcre_fullinfo(re.m_re, NULL, PCRE_INFO_SIZE, &size) >= 0) 56 | { 57 | if ((m_re = (pcre*)malloc(size))) 58 | { 59 | memcpy(m_re, re.m_re, size); 60 | memcpy(m_iOvector, re.m_iOvector, OVECCOUNT*sizeof(int)); 61 | m_iMatchCount = re.m_iMatchCount; 62 | m_bMatched = re.m_bMatched; 63 | m_subject = re.m_subject; 64 | m_iOptions = re.m_iOptions; 65 | } 66 | } 67 | } 68 | return *this; 69 | } 70 | 71 | CRegExp::~CRegExp() 72 | { 73 | Cleanup(); 74 | } 75 | 76 | CRegExp* CRegExp::RegComp(const char *re) 77 | { 78 | if (!re) 79 | return NULL; 80 | 81 | m_bMatched = false; 82 | m_iMatchCount = 0; 83 | const char *errMsg = NULL; 84 | int errOffset = 0; 85 | 86 | Cleanup(); 87 | 88 | m_re = pcre_compile(re, m_iOptions, &errMsg, &errOffset, NULL); 89 | if (!m_re) 90 | { 91 | m_pattern.clear(); 92 | CLog::Log(LOGERROR, "PCRE: %s. Compilation failed at offset %d in expression '%s'", 93 | errMsg, errOffset, re); 94 | return NULL; 95 | } 96 | 97 | m_pattern = re; 98 | 99 | return this; 100 | } 101 | 102 | int CRegExp::RegFind(const char* str, int startoffset) 103 | { 104 | m_bMatched = false; 105 | m_iMatchCount = 0; 106 | 107 | if (!m_re) 108 | { 109 | CLog::Log(LOGERROR, "PCRE: Called before compilation"); 110 | return -1; 111 | } 112 | 113 | if (!str) 114 | { 115 | CLog::Log(LOGERROR, "PCRE: Called without a string to match"); 116 | return -1; 117 | } 118 | 119 | m_subject = str; 120 | int rc = pcre_exec(m_re, NULL, str, strlen(str), startoffset, 0, m_iOvector, OVECCOUNT); 121 | 122 | if (rc<1) 123 | { 124 | switch(rc) 125 | { 126 | case PCRE_ERROR_NOMATCH: 127 | return -1; 128 | 129 | case PCRE_ERROR_MATCHLIMIT: 130 | CLog::Log(LOGERROR, "PCRE: Match limit reached"); 131 | return -1; 132 | 133 | default: 134 | CLog::Log(LOGERROR, "PCRE: Unknown error: %d", rc); 135 | return -1; 136 | } 137 | } 138 | m_bMatched = true; 139 | m_iMatchCount = rc; 140 | return m_iOvector[0]; 141 | } 142 | 143 | int CRegExp::GetCaptureTotal() 144 | { 145 | int c = -1; 146 | if (m_re) 147 | pcre_fullinfo(m_re, NULL, PCRE_INFO_CAPTURECOUNT, &c); 148 | return c; 149 | } 150 | 151 | char* CRegExp::GetReplaceString( const char* sReplaceExp ) 152 | { 153 | char *src = (char *)sReplaceExp; 154 | char *buf; 155 | char c; 156 | int no; 157 | size_t len; 158 | 159 | if( sReplaceExp == NULL || !m_bMatched ) 160 | return NULL; 161 | 162 | 163 | // First compute the length of the string 164 | int replacelen = 0; 165 | while ((c = *src++) != '\0') 166 | { 167 | if (c == '&') 168 | no = 0; 169 | else if (c == '\\' && isdigit(*src)) 170 | no = *src++ - '0'; 171 | else 172 | no = -1; 173 | 174 | if (no < 0) 175 | { 176 | // Ordinary character. 177 | if (c == '\\' && (*src == '\\' || *src == '&')) 178 | c = *src++; 179 | replacelen++; 180 | } 181 | else if (no < m_iMatchCount && (m_iOvector[no*2]>=0)) 182 | { 183 | // Get tagged expression 184 | len = m_iOvector[no*2+1] - m_iOvector[no*2]; 185 | replacelen += len; 186 | } 187 | } 188 | 189 | // Now allocate buf 190 | buf = (char *)malloc((replacelen + 1)*sizeof(char)); 191 | if( buf == NULL ) 192 | return NULL; 193 | 194 | char* sReplaceStr = buf; 195 | 196 | // Add null termination 197 | buf[replacelen] = '\0'; 198 | 199 | // Now we can create the string 200 | src = (char *)sReplaceExp; 201 | while ((c = *src++) != '\0') 202 | { 203 | if (c == '&') 204 | no = 0; 205 | else if (c == '\\' && isdigit(*src)) 206 | no = *src++ - '0'; 207 | else 208 | no = -1; 209 | 210 | if (no < 0) 211 | { 212 | // Ordinary character. 213 | if (c == '\\' && (*src == '\\' || *src == '&')) 214 | c = *src++; 215 | *buf++ = c; 216 | } 217 | else if (no < m_iMatchCount && (m_iOvector[no*2]>=0)) 218 | { 219 | // Get tagged expression 220 | len = m_iOvector[no*2+1] - m_iOvector[no*2]; 221 | strncpy(buf, m_subject.c_str()+m_iOvector[no*2], len); 222 | buf += len; 223 | } 224 | } 225 | 226 | return sReplaceStr; 227 | } 228 | 229 | std::string CRegExp::GetMatch(int iSub /* = 0 */) 230 | { 231 | if (iSub < 0 || iSub > m_iMatchCount) 232 | return ""; 233 | 234 | int pos = m_iOvector[(iSub*2)]; 235 | int len = m_iOvector[(iSub*2)+1] - pos; 236 | return m_subject.substr(pos, len); 237 | } 238 | 239 | bool CRegExp::GetNamedSubPattern(const char* strName, std::string& strMatch) 240 | { 241 | strMatch.clear(); 242 | int iSub = pcre_get_stringnumber(m_re, strName); 243 | if (iSub < 0) 244 | return false; 245 | strMatch = GetMatch(iSub); 246 | return true; 247 | } 248 | 249 | void CRegExp::DumpOvector(int iLog /* = LOGDEBUG */) 250 | { 251 | if (iLog < LOGDEBUG || iLog > LOGNONE) 252 | return; 253 | 254 | CStdString str = "{"; 255 | int size = GetSubCount(); // past the subpatterns is junk 256 | for (int i = 0; i <= size; i++) 257 | { 258 | CStdString t; 259 | t.Format("[%i,%i]", m_iOvector[(i*2)], m_iOvector[(i*2)+1]); 260 | if (i != size) 261 | t += ","; 262 | str += t; 263 | } 264 | str += "}"; 265 | CLog::Log(iLog, "regexp ovector=%s", str.c_str()); 266 | } 267 | --------------------------------------------------------------------------------