├── LICENSE ├── README.md ├── core ├── Anaglyph.cpp ├── Anaglyph.h ├── Audio.cpp ├── Audio.h ├── DelegateControl.cpp ├── DelegateControl.h ├── EventsEmitter.cpp ├── EventsEmitter.h ├── Filters.cpp ├── Filters.h ├── Instance.cpp ├── Instance.h ├── Interface.cpp ├── Interface.h ├── Media.cpp ├── Media.h ├── Mediaplayer.cpp ├── Mediaplayer.h ├── Options.h ├── Player.cpp ├── Player.h ├── Shaders.h ├── Video.cpp ├── Video.h ├── VideoShow.cpp ├── VideoShow.h ├── ViewThread.cpp ├── ViewThread.h ├── filter.h └── main.cpp ├── forms └── player.ui ├── logo ├── 1024 Logotype.png ├── 1024 Logotype.svg ├── 144 trprant.svg ├── 144.svg ├── 256 trprant.svg ├── 256.svg ├── 48 trprant.svg ├── 48.svg ├── 512 Logotype.svg ├── 512 trprant.svg ├── 512.svg ├── 72 trprant.svg ├── 72.svg ├── 96 trprant.svg └── 96.svg ├── player.pro ├── player.pro.user ├── scheme.png └── widgets ├── ControlPanel.cpp ├── ControlPanel.h ├── VideoSlider.cpp ├── VideoSlider.h ├── VideoWindow.cpp └── VideoWindow.h /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 SSbug 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | [![CodeFactor](https://www.codefactor.io/repository/github/ssbug696/opengl-media-player.-libvlc-and-qt/badge)](https://www.codefactor.io/repository/github/ssbug696/opengl-media-player.-libvlc-and-qt) 6 | 7 | #### Simple and efficient media player(qt,libvlc & c++) 8 | -- 9 | ##### What and why? 10 | 11 | ###### Convert YUV rendered on the GPU. High speed video processing. Support for 4K video. 12 | ###### To read the stream using VLC. Converting to GLSL shaders version 2.0. 13 | 14 | ####### Details showed on scheme ( scheme.png ) 15 | 16 | The player does not have a design, so the interface is only for testing =) 17 | 18 | -------------------------------------------------------------------------------- /core/Anaglyph.cpp: -------------------------------------------------------------------------------- 1 | #include "Anaglyph.h" 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | Anaglyph::Anaglyph(float Convergence, 8 | float EyeSeparation, 9 | float AspectRatio, 10 | float FOV, 11 | float NearClippingDistance, 12 | float FarClippingDistance 13 | ){ 14 | _flag = 0; 15 | _mConvergence = Convergence; 16 | _mEyeSeparation = EyeSeparation; 17 | _mAspectRatio = AspectRatio; 18 | _mFOV = FOV * 3.14 / 180.0f; 19 | _mNearClippingDistance = NearClippingDistance; 20 | _mFarClippingDistance = FarClippingDistance; 21 | } 22 | 23 | 24 | void Anaglyph::ApplyLeftFrustum() { 25 | 26 | if(_flag & 2) { 27 | top = _ltop; 28 | bottom = _lbottom; 29 | left = _lleft; 30 | right = _lright; 31 | } else { 32 | top = _mNearClippingDistance * tan(_mFOV/2); 33 | bottom = -top; 34 | 35 | float a = _mAspectRatio * tan(_mFOV/2) * _mConvergence; 36 | 37 | float b = a - _mEyeSeparation/2; 38 | float c = a + _mEyeSeparation/2; 39 | 40 | left = -b * _mNearClippingDistance/_mConvergence; 41 | right = c * _mNearClippingDistance/_mConvergence; 42 | 43 | _ltop = top; 44 | _lbottom= bottom; 45 | _lright = right; 46 | _lleft = left; 47 | 48 | _flag++; 49 | } 50 | 51 | // Set the Projection Matrix 52 | glMatrixMode(GL_PROJECTION); 53 | glLoadIdentity(); 54 | glFrustum(left, right, bottom, top, 55 | _mNearClippingDistance, _mFarClippingDistance); 56 | 57 | // Displace the world to right 58 | glMatrixMode(GL_MODELVIEW); 59 | glLoadIdentity(); 60 | glTranslatef(_mEyeSeparation/2, 0.0f, 0.0f); 61 | } 62 | 63 | void Anaglyph::ApplyRightFrustum() 64 | { 65 | if(_flag & 2) { 66 | top = _rtop; 67 | bottom = _rbottom; 68 | left = _rleft; 69 | right = _rright; 70 | } else { 71 | top = _mNearClippingDistance * tan(_mFOV/2); 72 | bottom = -top; 73 | 74 | float a = _mAspectRatio * tan(_mFOV/2) * _mConvergence; 75 | 76 | float b = a - _mEyeSeparation/2; 77 | float c = a + _mEyeSeparation/2; 78 | 79 | left = -c * _mNearClippingDistance/_mConvergence; 80 | right = b * _mNearClippingDistance/_mConvergence; 81 | 82 | _rtop = top; 83 | _rbottom= bottom; 84 | _rright = right; 85 | _rleft = left; 86 | 87 | _flag++; 88 | } 89 | 90 | glMatrixMode(GL_PROJECTION); 91 | glLoadIdentity(); 92 | glFrustum(left, right, bottom, top, 93 | _mNearClippingDistance, _mFarClippingDistance); 94 | 95 | glMatrixMode(GL_MODELVIEW); 96 | glLoadIdentity(); 97 | glTranslatef(-_mEyeSeparation/2, 0.0f, 0.0f); 98 | } 99 | -------------------------------------------------------------------------------- /core/Anaglyph.h: -------------------------------------------------------------------------------- 1 | #ifndef ANAGLYPH_H 2 | #define ANAGLYPH_H 3 | 4 | 5 | class Anaglyph { 6 | public: 7 | Anaglyph(float, float, float, float, float, float); 8 | void ApplyLeftFrustum(); 9 | void ApplyRightFrustum(); 10 | 11 | private: 12 | float _mConvergence; 13 | float _mEyeSeparation; 14 | float _mAspectRatio; 15 | float _mFOV; 16 | float _mNearClippingDistance; 17 | float _mFarClippingDistance; 18 | 19 | float _rtop, _rbottom, _rleft, _rright, 20 | _ltop, _lbottom, _lleft, _lright; 21 | 22 | float top, bottom, left, right; 23 | 24 | short _flag; 25 | }; 26 | 27 | #endif // ANAGLYPH_H 28 | -------------------------------------------------------------------------------- /core/Audio.cpp: -------------------------------------------------------------------------------- 1 | #include "vlc/vlc.h" 2 | #include "Audio.h" 3 | #include "Mediaplayer.h" 4 | 5 | 6 | Audio::Audio(libvlc_media_player_t * player) 7 | { 8 | mp = player; 9 | } 10 | 11 | Audio::~Audio(){ 12 | delete mp; 13 | } 14 | 15 | bool Audio::getMute() const { 16 | bool mute = false; 17 | if (mp) { 18 | mute = libvlc_audio_get_mute(mp); 19 | } 20 | return mute; 21 | } 22 | 23 | void Audio::setVolume(int volume){ 24 | if (mp) { 25 | if (volume != getVolume()) { 26 | libvlc_audio_set_volume(mp, volume); 27 | } 28 | } 29 | } 30 | 31 | bool Audio::toogleMute() const{ 32 | if (mp) { 33 | libvlc_audio_toggle_mute(mp); 34 | } 35 | return getMute(); 36 | } 37 | 38 | int Audio::getVolume(){ 39 | int volume = -1; 40 | if (mp) { 41 | volume = libvlc_audio_get_volume(mp); 42 | } 43 | 44 | return volume; 45 | } 46 | -------------------------------------------------------------------------------- /core/Audio.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_H 2 | #define AUDIO_H 3 | #include 4 | 5 | 6 | class MediaPlayer; 7 | 8 | struct libvlc_media_player_t; 9 | /*! 10 | * \brief The Audio class 11 | */ 12 | class Audio { 13 | public: 14 | Audio(libvlc_media_player_t *); 15 | ~Audio(); 16 | bool getMute() const; 17 | bool toogleMute() const; 18 | void setVolume(int volume); 19 | int getVolume(); 20 | 21 | private: 22 | libvlc_media_player_t * mp; 23 | }; 24 | 25 | #endif // AUDIO_H 26 | -------------------------------------------------------------------------------- /core/DelegateControl.cpp: -------------------------------------------------------------------------------- 1 | #include "DelegateControl.h" 2 | #include "Mediaplayer.h" 3 | 4 | 5 | DelegateControl::DelegateControl(Mediaplayer * mp){ 6 | _mp = mp; 7 | } 8 | 9 | 10 | void DelegateControl::play(){ 11 | //_mp->play(); 12 | } 13 | 14 | 15 | void DelegateControl::pause(){ 16 | //_mp->pause(); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /core/DelegateControl.h: -------------------------------------------------------------------------------- 1 | #ifndef DELEGATECONTROL_H 2 | #define DELEGATECONTROL_H 3 | #include 4 | 5 | struct libvlc_event_t; 6 | struct libvlc_event_manager_t; 7 | struct libvlc_media_t; 8 | struct libvlc_media_player_t; 9 | struct Mediaplayer; 10 | 11 | 12 | class DelegateControl : public QObject { 13 | Q_OBJECT 14 | public: 15 | // explicit DelegateControl(QObject *parent = 0); 16 | DelegateControl(Mediaplayer *); 17 | 18 | void play(); 19 | void pause(); 20 | Mediaplayer * _mp; 21 | 22 | signals: 23 | 24 | public slots: 25 | }; 26 | 27 | #endif // DELEGATECONTROL_H 28 | -------------------------------------------------------------------------------- /core/EventsEmitter.cpp: -------------------------------------------------------------------------------- 1 | #include "EventsEmitter.h" 2 | #include "Mediaplayer.h" 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | void callbackEvents(const libvlc_event_t *, void *); 9 | EventsEmitter * e_emitter; 10 | 11 | EventsEmitter::EventsEmitter(QObject *parent) : QObject(parent) 12 | {} 13 | 14 | 15 | EventsEmitter::EventsEmitter(Interface * interface) { 16 | _interface = interface; 17 | e_emitter = this; 18 | events = libvlc_media_player_event_manager(_interface->ptrP->mediaPlayer->getInstance()); 19 | bindEvents(); 20 | } 21 | 22 | 23 | void EventsEmitter::bindEvents() { 24 | this->connect(this, SIGNAL(Playing()), _interface, SLOT(updateStatusControlPanel())); 25 | QList list; 26 | list << libvlc_MediaPlayerMediaChanged 27 | << libvlc_MediaPlayerNothingSpecial 28 | << libvlc_MediaPlayerOpening 29 | << libvlc_MediaPlayerBuffering 30 | << libvlc_MediaPlayerPlaying 31 | << libvlc_MediaPlayerPaused 32 | << libvlc_MediaPlayerStopped 33 | << libvlc_MediaPlayerForward 34 | << libvlc_MediaPlayerBackward 35 | << libvlc_MediaPlayerEndReached 36 | << libvlc_MediaPlayerEncounteredError 37 | << libvlc_MediaPlayerTimeChanged 38 | << libvlc_MediaPlayerPositionChanged 39 | << libvlc_MediaPlayerSeekableChanged 40 | << libvlc_MediaPlayerPausableChanged 41 | << libvlc_MediaPlayerTitleChanged 42 | << libvlc_MediaPlayerSnapshotTaken 43 | << libvlc_MediaPlayerLengthChanged 44 | << libvlc_MediaPlayerVout; 45 | 46 | foreach(const libvlc_event_e &event, list) { 47 | libvlc_event_attach(events, event, &callbackEvents, this); 48 | } 49 | // libvlc_event_attach(events, libvlc_MediaPlayerSnapshotTaken, &callbackEvents, this); 50 | } 51 | 52 | 53 | void EventsEmitter::unbindEvents(){} 54 | 55 | 56 | void EventsEmitter::Vout(){ 57 | _interface->outFinishedEvent(); 58 | } 59 | 60 | void EventsEmitter::PositionChanged(){ 61 | std::cout << "PositionChanged event \n" << std::endl; 62 | } 63 | 64 | void EventsEmitter::Buffering(){ 65 | _interface->bufferingEvent(); 66 | } 67 | 68 | void EventsEmitter::TimeChanged(){ 69 | _interface->timeChangeEvent(); 70 | } 71 | 72 | 73 | void EventsEmitter::Playing(){ 74 | _interface->playingEvent(); 75 | } 76 | 77 | 78 | void EventsEmitter::Opening(){ 79 | _interface->openEvent(); 80 | } 81 | 82 | 83 | void EventsEmitter::Stopped(){ 84 | qDebug() << "Stopped event \n"; 85 | } 86 | 87 | void callbackEvents(const libvlc_event_t *e, void *data){ 88 | MediaPlayer *core = (MediaPlayer *)data; 89 | switch(e->type) 90 | { 91 | case libvlc_MediaPlayerMediaChanged: 92 | qDebug() << "emit action \n"; 93 | break; 94 | case libvlc_MediaParsedChanged: 95 | qDebug() << "libvlc_MediaParsedChanged action \n"; 96 | break; 97 | case libvlc_MediaPlayerOpening: 98 | e_emitter->Opening(); 99 | break; 100 | case libvlc_MediaPlayerBuffering: 101 | e_emitter->Buffering(); 102 | break; 103 | case libvlc_MediaPlayerPlaying: 104 | e_emitter->Playing(); 105 | break; 106 | case libvlc_MediaPlayerPaused: 107 | qDebug() << "MediaPlayerPaused \n"; 108 | break; 109 | case libvlc_MediaPlayerStopped: 110 | e_emitter->Stopped(); 111 | break; 112 | case libvlc_MediaPlayerForward: 113 | qDebug() << "MediaPlayerForward \n"; 114 | break; 115 | case libvlc_MediaPlayerBackward: 116 | qDebug() << "MediaPlayerBackward \n"; 117 | break; 118 | case libvlc_MediaPlayerEndReached: 119 | qDebug() << "MediaPlayerEndReached \n"; 120 | break; 121 | case libvlc_MediaPlayerEncounteredError: 122 | qDebug() << "MediaPlayerEncounteredError \n"; 123 | break; 124 | case libvlc_MediaPlayerTimeChanged: 125 | e_emitter->TimeChanged(); 126 | break; 127 | case libvlc_MediaPlayerPositionChanged: 128 | e_emitter->PositionChanged(); 129 | break; 130 | case libvlc_MediaPlayerSeekableChanged: 131 | qDebug() << "MediaPlayerSeekableChanged \n"; 132 | break; 133 | case libvlc_MediaPlayerPausableChanged: 134 | qDebug() << "MediaPlayerPausableChanged \n"; 135 | break; 136 | case libvlc_MediaPlayerTitleChanged: 137 | qDebug() << "MediaPlayerTitleChanged \n"; 138 | break; 139 | case libvlc_MediaPlayerSnapshotTaken: 140 | qDebug() << "emit action \n"; 141 | break; 142 | case libvlc_MediaPlayerLengthChanged: 143 | qDebug() << "MediaPlayerLengthChanged \n"; 144 | break; 145 | case libvlc_MediaPlayerVout: 146 | e_emitter->Vout(); 147 | break; 148 | default: 149 | break; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /core/EventsEmitter.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTSEMITTER_H 2 | #define EVENTSEMITTER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | struct libvlc_event_t; 11 | class Interface; 12 | 13 | class EventsEmitter : public QObject { 14 | Q_OBJECT 15 | 16 | private: 17 | Interface * _interface; 18 | 19 | public: 20 | explicit EventsEmitter(QObject *parent = 0); 21 | EventsEmitter(Interface *); 22 | 23 | // void callbackEvents(const libvlc_event_t *, void *); 24 | libvlc_event_manager_t * events; 25 | void bindEvents(); 26 | void unbindEvents(); 27 | void Playing(); 28 | void PositionChanged(); 29 | void TimeChanged(); 30 | void Paused(); 31 | void Stopped(); 32 | void Opening(); 33 | void Buffering(); 34 | void Vout(); 35 | 36 | signals: 37 | public slots: 38 | }; 39 | 40 | #endif // EVENTSEMITTER_H 41 | -------------------------------------------------------------------------------- /core/Filters.cpp: -------------------------------------------------------------------------------- 1 | #include "Filters.h" 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | Filters::Filters() { 8 | _filters_collection[QString("no-filter")] = 0; 9 | //_filters_collection[QString("anaglyph-filter")]=14; 10 | 11 | _filters_args[0]="vmem"; 12 | _filters_args[1]="-q"; 13 | _filters_args[2]="--quiet"; 14 | _filters_args[3]="--ignore-config"; 15 | _filters_args[4]="--vout"; 16 | _filters_args[5]="--no-xlib"; 17 | _filters_args[6]="-I"; 18 | _filters_args[7]="dumy"; 19 | _filters_args[8]="--no-video-title-show"; 20 | _filters_args[9]="-v"; 21 | _filters_args[10]="--intf=dummy"; 22 | _filters_args[11]="--no-osd"; 23 | _filters_args[12]="--no-loop"; 24 | _filters_args[13]="--drop-late-frames"; 25 | _filters_args[14]="--video-filter=Anaglyph"; 26 | } 27 | 28 | 29 | void Filters::setFilter(int id) { 30 | _filters.clear(); 31 | 32 | if(std::find(_activeFilters.begin(), _activeFilters.end(), id) == _activeFilters.end()){ 33 | _activeFilters.insert(_activeFilters.end(), id); 34 | } 35 | 36 | for(unsigned it=0; it!=_activeFilters.size(); it++){ 37 | _filters.insert(_filters.end(), _filters_args[_activeFilters[it]]); 38 | } 39 | 40 | //STUB 41 | std::cout << "Current filters list "; 42 | for(int i=0;i!=_filters.size();i++){ 43 | std::cout << _filters[i] << " "; 44 | } 45 | std::cout << "\n"; 46 | } 47 | 48 | 49 | void Filters::updateListFilters() { 50 | setFilter(0); 51 | } 52 | 53 | 54 | bool Filters::checkEnable(int id) { 55 | if(std::find(_activeFilters.begin(), _activeFilters.end(), id) == _activeFilters.end()){ 56 | return false; 57 | } else return true; 58 | } 59 | 60 | 61 | void Filters::toogleFilter(int id) { 62 | if(std::find(_activeFilters.begin(), _activeFilters.end(), id) == _activeFilters.end()){ 63 | setFilter(id); 64 | } else removeFilter(id); 65 | } 66 | 67 | 68 | void Filters::removeFilter(int id ) { 69 | if(std::find(_activeFilters.begin(), _activeFilters.end(), id) != _activeFilters.end()){ 70 | _activeFilters.erase(_activeFilters.begin()+1); 71 | updateListFilters(); 72 | } 73 | } 74 | 75 | 76 | std::vector & Filters::getArgv() { 77 | return _filters; 78 | } 79 | -------------------------------------------------------------------------------- /core/Filters.h: -------------------------------------------------------------------------------- 1 | #ifndef FILTERS_H 2 | #define FILTERS_H 3 | 4 | #endif // FILTERS 5 | #include 6 | #include 7 | 8 | 9 | class Filters { 10 | public: 11 | static const int 12 | P_VMEM =0, 13 | P_Q =1, 14 | P_QUIET =2, 15 | P_IGNORE_CONFIG=3, 16 | P_VOUT =4, 17 | P_XLIB =5, 18 | P_I =6, 19 | P_DUMY =7, 20 | P_NO_VIDEO_TITLE_SHOW=8, 21 | P_V =9, 22 | P_INTF_DUMMY=10, 23 | P_NO_OSD=11, 24 | P_NO_LOOP=12, 25 | P_DROP_LATE_FRAME=13, 26 | P_ANAGLYPH_FILTER=14; 27 | 28 | std::vector & getArgv(); 29 | 30 | 31 | Filters(); 32 | void setFilter(int); 33 | void removeFilter(int); 34 | void updateListFilters(); 35 | bool checkEnable(int); 36 | void toogleFilter(int); 37 | 38 | 39 | private: 40 | std::vector _filters; 41 | QMap _filters_collection; 42 | QMap _filters_args; 43 | std::vector _activeFilters; 44 | }; 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /core/Instance.cpp: -------------------------------------------------------------------------------- 1 | #include "Instance.h" 2 | #include 3 | #include 4 | #include 5 | #include "Filters.h" 6 | #include 7 | #include 8 | 9 | 10 | Instance::Instance(std::vector & filters){ 11 | const char * argv[filters.size()]; 12 | for(int i=0;i<=filters.size();i++){ 13 | argv[i]=filters[i]; 14 | } 15 | _instance=libvlc_new(filters.size(), argv); 16 | } 17 | 18 | 19 | libvlc_instance_t * Instance::getInstance(){ 20 | return _instance; 21 | } 22 | 23 | 24 | Instance::~Instance(){ 25 | delete _instance; 26 | } 27 | 28 | 29 | void Instance::showActiveModules(){ 30 | libvlc_module_description_t *t =libvlc_video_filter_list_get(_instance); 31 | qDebug() << QString::fromStdString( (char *)t->psz_longname ); 32 | qDebug() << QString::fromStdString( (char *)t->p_next->psz_longname ); 33 | 34 | while(t){ 35 | qDebug() << QString::fromStdString( (char *)t->psz_shortname ); 36 | t=t->p_next; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /core/Instance.h: -------------------------------------------------------------------------------- 1 | #ifndef INSTANCE_H 2 | #define INSTANCE_H 3 | #include 4 | #include 5 | 6 | 7 | class Filters; 8 | struct libvlc_module_description_t; 9 | struct libvlc_instance_t; 10 | 11 | /*! 12 | * \brief The Instance class 13 | */ 14 | class Instance: public QObject { 15 | Q_OBJECT 16 | public: 17 | Instance(std::vector &); 18 | 19 | ~Instance(); 20 | 21 | libvlc_instance_t * getInstance(); 22 | void showActiveModules(); 23 | 24 | private: 25 | libvlc_instance_t * _instance; 26 | }; 27 | 28 | #endif // INSTANCE_H 29 | -------------------------------------------------------------------------------- /core/Interface.cpp: -------------------------------------------------------------------------------- 1 | #include "Interface.h" 2 | #include "Player.h" 3 | #include "Filters.h" 4 | #include "VideoShow.h" 5 | #include "EventsEmitter.h" 6 | #include "ViewThread.h" 7 | 8 | #include "widgets/VideoSlider.h" 9 | #include "widgets/VideoWindow.h" 10 | #include "widgets/ControlPanel.h" 11 | #include 12 | 13 | #include 14 | #include 15 | #include "QTime" 16 | #include "QDebug" 17 | #include "QTimer" 18 | 19 | #include "Video.h" 20 | #include "Audio.h" 21 | #include "Media.h" 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | struct libvlc_event_t; 32 | struct libvlc_event_manager_t; 33 | struct libvlc_media_t; 34 | struct libvlc_media_player_t; 35 | struct libvlc_instance_t; 36 | struct libvlc_new; 37 | 38 | 39 | QTimer *timer; 40 | QMutex mutex; 41 | 42 | /*! 43 | * \brief Interface::Interface 44 | * \param mp 45 | */ 46 | Interface::Interface(Player * mp){ 47 | //_videoSlider = new VideoSlider(mp); 48 | _videoWindow = new VideoWindow(mp); 49 | _controlPanel = new ControlPanel(mp); 50 | 51 | // parent->setWindowState(Qt::WindowFullScreen); 52 | 53 | windowW=800; 54 | windowH=620; 55 | 56 | _winID = _videoWindow->videoWindow->winId(); 57 | 58 | view = new VideoShow(mp); 59 | 60 | showMediaThread = new ViewThread(view); 61 | thread = new QThread(); 62 | showMediaThread->moveToThread(thread); 63 | thread->start(); 64 | showMediaThread->run(); 65 | _is_pause_event = false; 66 | _time_stopped = 0; 67 | 68 | 69 | 70 | scaleX = (double)_videoWindow->videoWindow->width()/(double)windowW; 71 | scaleY = (double)_videoWindow->videoWindow->height()/(double)windowH; 72 | 73 | 74 | ptrP = mp; 75 | this->connect(_controlPanel->ratio, SIGNAL(clicked()), this, SLOT(changeRatio())); 76 | this->connect(_controlPanel->mute, SIGNAL(clicked()), this, SLOT(mute())); 77 | this->connect(_controlPanel->open, SIGNAL(pressed()), this, SLOT(openLocal())); 78 | this->connect(_controlPanel->play, SIGNAL(pressed()), this, SLOT(play())); 79 | this->connect(_controlPanel->full, SIGNAL(pressed()), this, SLOT(fullscreen())); 80 | this->connect(_controlPanel->pause, SIGNAL(clicked()), this, SLOT(pause())); 81 | this->connect(_controlPanel->anaglyph, SIGNAL(clicked()), showMediaThread, SLOT(activeAnaglyph())); 82 | 83 | 84 | 85 | this->connect(_controlPanel->volumeLevelSlider, SIGNAL(sliderMoved(int)), this, SLOT(valueChange(int))); 86 | this->connect(_controlPanel->volumeLevelSlider, SIGNAL(valueChanged(int)), this, SLOT(valueChange(int))); 87 | this->connect(_controlPanel->progressSlider, SIGNAL(sliderReleased()), this, SLOT(trackSlider())); 88 | this->connect(_controlPanel->anaglyph, SIGNAL(pressed()), this, SLOT(enabled3d())); 89 | this->connect(mp, SIGNAL(emitResizeEvent(QResizeEvent *)), this, SLOT(resizeEvent(QResizeEvent *))); 90 | } 91 | 92 | 93 | void Interface::changeRatio(){ 94 | view->changeRatio(); 95 | } 96 | 97 | 98 | /*! 99 | * \brief Interface::mute 100 | */ 101 | void Interface::mute(){ 102 | ptrP->mediaPlayer->mute(); 103 | } 104 | 105 | 106 | void Interface::triggerSliderMove(){ 107 | qDebug() << "slide \n"; 108 | } 109 | 110 | 111 | void Interface::openEvent(){ 112 | qDebug() << "open event \n"; 113 | } 114 | 115 | void Interface::fullscreen(){ 116 | ptrP->setWindowState(Qt::WindowFullScreen); 117 | //ptrP->setWindowState( Qt::WindowNoState); 118 | } 119 | 120 | 121 | void Interface::play(){ 122 | if(_is_pause_event){ 123 | // Here you can update params render video. 124 | //ptrP->instance = new Instance(ptrP->filters->getArgv()); 125 | ptrP->mediaPlayer = new MediaPlayer(ptrP->instance); 126 | ptrP->mediaPlayer->setPosition(_time_stopped); 127 | ptrP->media = new Media(ptrP->instance, _source_path); 128 | ptrP->mediaPlayer = new MediaPlayer(ptrP->instance); 129 | ptrP->mediaPlayer->open(ptrP->media, _videoWindow->videoWindow->winId(), _source_path, view, false); 130 | 131 | 132 | // Bind new play event 133 | this->connect(_controlPanel->play, SIGNAL(released()), ptrP->mediaPlayer, SLOT(play())); 134 | 135 | libvlc_media_player_navigate(ptrP->mediaPlayer->_mp, _time_stopped); 136 | libvlc_media_player_set_position(ptrP->mediaPlayer->_mp, _time_stopped); 137 | libvlc_media_player_set_time(ptrP->mediaPlayer->_mp, _time_stopped); 138 | } 139 | } 140 | 141 | void Interface::playEvent(){ 142 | qDebug() << "play event \n"; 143 | } 144 | 145 | 146 | void Interface::playingEvent(){ 147 | qDebug() << "playing event \n"; 148 | } 149 | 150 | 151 | void Interface::stopEvent(){ 152 | qDebug() << "stop event \n"; 153 | } 154 | 155 | 156 | void Interface::bufferingEvent(){ 157 | qDebug() <<"buffering event \n"; 158 | } 159 | 160 | 161 | void Interface::outFinishedEvent(){ 162 | qDebug() << "outFinished event \n"; 163 | } 164 | 165 | 166 | void Interface::timeChangeEvent(){ 167 | getLastTime(); 168 | } 169 | 170 | void Interface::updateStatusControlPanel(){ 171 | timer = new QTimer(this); 172 | std::cout << "EMIT success!" << std::endl; 173 | 174 | int length_track = ptrP->mediaPlayer->length(); 175 | int current_progress = ptrP->mediaPlayer->getTime(); 176 | 177 | int h = ((length_track/1000)/60)/60; 178 | int m = (length_track/1000)/60; 179 | int s = length_track/1000; 180 | int d = 0; 181 | if(s>60){ 182 | d=m*60; 183 | s-=d; 184 | } 185 | 186 | QString str; 187 | str.append(QString::number(m)); 188 | str+=':'; 189 | if(s<10){ 190 | str+='0'; 191 | } 192 | str.append(QString::number(s)); 193 | 194 | 195 | _controlPanel->progressSlider->setMaximum(length_track); 196 | _controlPanel->progressSlider->setRange(0, length_track); 197 | _controlPanel->startTime->setText(str); 198 | } 199 | 200 | 201 | /*! 202 | * \brief Interface::openLocal 203 | */ 204 | void Interface::openLocal(){ 205 | 206 | const QString tr="Open file"; 207 | QString file = 208 | QFileDialog::getOpenFileName(ptrP->widget, tr , QDir::homePath(), QString("Multimedia files(*)")); 209 | 210 | if (file.isEmpty()) 211 | return; 212 | 213 | ptrP->mediaPlayer->release(); 214 | ptrP->mediaPlayer = new MediaPlayer(ptrP->instance); 215 | ptrP->media = new Media(ptrP->instance, file); 216 | ptrP->mediaPlayer->open(ptrP->media, _winID, file, view, true); 217 | ptrP->eventManager = new EventsEmitter(this); 218 | _is_pause_event = false; 219 | } 220 | 221 | 222 | void Interface::getLastTime(){ 223 | int length_track = ptrP->mediaPlayer->length(); 224 | 225 | std::cout << length_track << std::endl; 226 | _controlPanel->progressSlider->setRange(0, length_track); 227 | 228 | int current_progress = ptrP->mediaPlayer->getTime(); 229 | 230 | if(!_controlPanel->volumeLevelSlider->hasTracking()){ 231 | _controlPanel->progressSlider->setValue(current_progress); 232 | } 233 | 234 | int h = ((current_progress/1000)/60)/60; 235 | int m = (current_progress/1000)/60; 236 | int s = current_progress/1000; 237 | int d = 0; 238 | if(s>60){ 239 | d=m*60; 240 | s-=d; 241 | } 242 | 243 | QString str; 244 | str.append(QString::number(m)); 245 | str+=':'; 246 | if(s<10){ 247 | str+='0'; 248 | } 249 | str.append(QString::number(s)); 250 | _controlPanel->startTime->setText(str); 251 | } 252 | 253 | 254 | void Interface::resizeEvent(QResizeEvent * event){ 255 | int vWidth = ptrP->width()*scaleX, 256 | vHeight = ptrP->height()*scaleY; 257 | 258 | view->setFixedWidth(vWidth); 259 | view->setFixedHeight(vHeight); 260 | 261 | int coef_up_w = ptrP->width()/600, 262 | coef_up_h = ptrP->height()/500; 263 | 264 | _controlPanel->widget->setGeometry( 265 | QRect( 266 | (ptrP->width() * 0.07 ) * coef_up_w, 267 | (ptrP->height() * 0.8 ) * coef_up_h, 268 | ptrP->width() * 0.9, 269 | 100 270 | ) 271 | ); 272 | 273 | } 274 | 275 | 276 | /*! 277 | * \brief Interface::valueChange 278 | */ 279 | void Interface::valueChange(int currentVolume){ 280 | ptrP->mediaPlayer->voice(currentVolume); 281 | } 282 | 283 | /*! 284 | * \brief Interface::trackSlider 285 | */ 286 | void Interface::trackSlider() 287 | { 288 | float value = _controlPanel->progressSlider->value(); 289 | ptrP->mediaPlayer->setPosition(value); 290 | } 291 | 292 | 293 | void Interface::eventsEmitter(QString event = "default"){ 294 | } 295 | 296 | // Pause and flush data from memory 297 | void Interface::pause(){ 298 | // Get current time 299 | _time_stopped = ptrP->mediaPlayer->getTime(); 300 | // Add 100ms for remove time event. It's just simple hack =) 301 | _time_stopped += 100; 302 | // Get path to stopped movie 303 | _source_path = ptrP->media->_locationSource; 304 | // Disconnect play event if media-player class and remove him 305 | this->disconnect(_controlPanel->play, SIGNAL(released()), ptrP->mediaPlayer, SLOT(play())); 306 | ptrP->mediaPlayer->release(); 307 | 308 | _is_pause_event = true; 309 | } 310 | 311 | -------------------------------------------------------------------------------- /core/Interface.h: -------------------------------------------------------------------------------- 1 | #ifndef INTERFACE_H 2 | #define INTERFACE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class Player; 9 | class VideoSlider; 10 | class VideoWindow; 11 | class ControlPanel; 12 | class EventsEmitter; 13 | class VideoShow; 14 | class ViewThread; 15 | class QString; 16 | 17 | struct libvlc_event_t; 18 | struct libvlc_event_manager_t; 19 | struct libvlc_media_t; 20 | struct libvlc_media_player_t; 21 | 22 | class Interface: public QObject { 23 | Q_OBJECT 24 | public: 25 | Interface(Player *); 26 | Player *ptrP; 27 | double scaleX; 28 | double scaleY; 29 | int windowW; 30 | int windowH; 31 | 32 | QThread *thread; 33 | 34 | VideoShow * view; 35 | ViewThread * showMediaThread; 36 | 37 | public slots: 38 | void openLocal(); 39 | void mute(); 40 | void valueChange(int); 41 | void trackSlider(); 42 | void getLastTime(); 43 | void eventsEmitter(QString); 44 | void updateStatusControlPanel(); 45 | void resizeEvent(QResizeEvent *); 46 | void changeRatio(); 47 | 48 | void play(); 49 | void playEvent(); 50 | void openEvent(); 51 | void playingEvent(); 52 | void stopEvent(); 53 | void bufferingEvent(); 54 | void outFinishedEvent(); 55 | void timeChangeEvent(); 56 | void pause(); 57 | void triggerSliderMove(); 58 | 59 | private slots: 60 | void fullscreen(); 61 | 62 | private: 63 | EventsEmitter * eEmitter; 64 | int _winID; 65 | ControlPanel * _controlPanel; 66 | VideoSlider * _videoSlider; 67 | VideoWindow * _videoWindow; 68 | bool _is_pause_event; 69 | int _time_stopped; 70 | QString _source_path; 71 | 72 | }; 73 | 74 | #endif // INTERFACE_H 75 | -------------------------------------------------------------------------------- /core/Media.cpp: -------------------------------------------------------------------------------- 1 | #include "Media.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /* 9 | #include 10 | #include 11 | #include 12 | */ 13 | 14 | #include "Instance.h" 15 | 16 | 17 | /*! 18 | * \brief Media::Media 19 | * \param location 20 | * \param locFileFlag 21 | * \param instance 22 | */ 23 | Media::Media(Instance * instance, QString path){ 24 | Init(instance, path) ; 25 | } 26 | 27 | /*! 28 | * \brief Media::Init 29 | * \param location 30 | * \param localFile 31 | * \param instance 32 | */ 33 | void Media::Init(Instance *inst, QString & path){ 34 | _instance = inst->getInstance(); 35 | _locationSource = path; 36 | _media = libvlc_media_new_path(inst->getInstance(), path.toUtf8().data()); 37 | 38 | } 39 | 40 | void Media::setMediaToPlaylist(QString path){ 41 | /* path = QDir::toNativeSeparators(path); 42 | libvlc_media_t * ptr_media = libvlc_media_new_path(_instance, path.toUtf8().data()); 43 | libvlc_media_add_media(_media_list, ptr_media); 44 | */ 45 | } 46 | 47 | 48 | /*! 49 | * \brief Media::getMedia 50 | * \return 51 | */ 52 | libvlc_media_t * Media::getMedia() const { 53 | return _media; 54 | } 55 | 56 | int Media::getMediaListCount() const { 57 | //return libvlc_media_count(_media_list); 58 | } 59 | 60 | /*! 61 | * \brief Media::getEventManager 62 | * \return 63 | */ 64 | libvlc_event_manager_t * Media::getEventManager() const { 65 | return _events; 66 | } 67 | 68 | /*! 69 | * \brief Media::~Media 70 | */ 71 | Media::~Media(){ 72 | libvlc_media_release(_media); 73 | } 74 | -------------------------------------------------------------------------------- /core/Media.h: -------------------------------------------------------------------------------- 1 | #ifndef MEDIA_H 2 | #define MEDIA_H 3 | #include 4 | 5 | struct libvlc_event_t; 6 | struct libvlc_event_manager_t; 7 | struct libvlc_media_t; 8 | struct libvlc_instance_t; 9 | struct libvlc_list_add_media; 10 | 11 | 12 | class Instance; 13 | 14 | /*! 15 | * \brief The Media class 16 | */ 17 | class Media : public QObject { 18 | Q_OBJECT 19 | public: 20 | Media(Instance *, QString); 21 | ~Media(); 22 | 23 | void Init(Instance *, QString &); 24 | libvlc_media_t * getMedia() const; 25 | libvlc_event_manager_t * getEventManager() const; 26 | int getMediaListCount() const; 27 | void setMediaToPlaylist(QString); 28 | QString _locationSource; 29 | 30 | signals: 31 | public slots: 32 | 33 | private: 34 | libvlc_media_t * _media; 35 | libvlc_event_manager_t *_events; 36 | libvlc_instance_t * _instance; 37 | }; 38 | 39 | #endif // MEDIA_H 40 | -------------------------------------------------------------------------------- /core/Mediaplayer.cpp: -------------------------------------------------------------------------------- 1 | #include "Mediaplayer.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Video.h" 8 | #include "Audio.h" 9 | #include "Media.h" 10 | #include "VideoShow.h" 11 | #include "Instance.h" 12 | #include "iostream" 13 | #include 14 | #include 15 | #include 16 | #include "stdio.h" 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | struct libvlc_event_t; 31 | struct libvlc_event_manager_t; 32 | struct libvlc_media_t; 33 | struct libvlc_media_player_t; 34 | struct libvlc_instance_t; 35 | struct libvlc_new; 36 | struct libvlc_module_description_t; //* libvlc_video_filter_list_get 37 | 38 | const int WIDTH = 5000; 39 | const int HEIGHT = 5000; 40 | unsigned char * data_pixels = new unsigned char[ WIDTH * HEIGHT * 3]; 41 | 42 | bool status=false; 43 | 44 | 45 | /*! 46 | * \brief MediaPlayer::MediaPlayer 47 | * \param instance 48 | * \param ui 49 | */ 50 | MediaPlayer::MediaPlayer(Instance * instance){ 51 | _mp = libvlc_media_player_new(instance->getInstance()); 52 | _instance = instance; 53 | _mpEvents = libvlc_media_player_event_manager(_mp); 54 | 55 | _mpVideo = std::unique_ptr