diff --git a/example-http-stream/Makefile b/example-http-stream/Makefile new file mode 100755 index 0000000..7a7fe8b --- /dev/null +++ b/example-http-stream/Makefile @@ -0,0 +1,13 @@ +# Attempt to load a config.make file. +# If none is found, project defaults in config.project.make will be used. +ifneq ($(wildcard config.make),) + include config.make +endif + +# make sure the the OF_ROOT location is defined +ifndef OF_ROOT + OF_ROOT=../../.. +endif + +# call the project makefile! +include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk diff --git a/example-http-stream/addons.make b/example-http-stream/addons.make new file mode 100755 index 0000000..b5a69e9 --- /dev/null +++ b/example-http-stream/addons.make @@ -0,0 +1 @@ +ofxOMXPlayer \ No newline at end of file diff --git a/example-http-stream/src/main.cpp b/example-http-stream/src/main.cpp new file mode 100755 index 0000000..2e9cbcb --- /dev/null +++ b/example-http-stream/src/main.cpp @@ -0,0 +1,8 @@ +#include "ofMain.h" +#include "ofApp.h" + +int main() +{ + ofSetupOpenGL(1280, 720, OF_WINDOW); + ofRunApp( new ofApp()); +} \ No newline at end of file diff --git a/example-http-stream/src/ofApp.cpp b/example-http-stream/src/ofApp.cpp new file mode 100755 index 0000000..4ecc6bc --- /dev/null +++ b/example-http-stream/src/ofApp.cpp @@ -0,0 +1,60 @@ +#include "ofApp.h" + +//-------------------------------------------------------------- +void ofApp::setup() +{ + ofSetLogLevel(OF_LOG_VERBOSE); + + string v1 = "https://devimages.apple.com.edgekey.net/samplecode/avfoundationMedia/AVFoundationQueuePlayer_HLS2/master.m3u8"; + string v2 = "rtsp://192.168.200.43:1935/vod/sample.mp4"; + string v3 = "http://192.168.200.43:1935/vod/mp4:sample.mp4/playlist.m3u8"; + string v4 = "http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"; + + + string videoPath = v1; + + //Somewhat like ofFboSettings we may have a lot of options so this is the current model + ofxOMXPlayerSettings settings; + settings.videoPath = videoPath; + settings.useHDMIForAudio = true; //default true + settings.enableTexture = true; //default true + settings.enableLooping = true; //default true + settings.enableAudio = true; //default true, save resources by disabling + //settings.doFlipTexture = true; //default false + + + //so either pass in the settings + omxPlayer.setup(settings); + + //or live with the defaults + //omxPlayer.loadMovie(videoPath); + +} + + + +//-------------------------------------------------------------- +void ofApp::update() +{ + +} + + +//-------------------------------------------------------------- +void ofApp::draw(){ + if(!omxPlayer.isTextureEnabled()) + { + return; + } + + omxPlayer.draw(0, 0, ofGetWidth(), ofGetHeight()); + + //draw a smaller version in the lower right + int scaledHeight = omxPlayer.getHeight()/4; + int scaledWidth = omxPlayer.getWidth()/4; + omxPlayer.draw(ofGetWidth()-scaledWidth, ofGetHeight()-scaledHeight, scaledWidth, scaledHeight); + + ofDrawBitmapStringHighlight(omxPlayer.getInfo(), 60, 60, ofColor(ofColor::black, 90), ofColor::yellow); +} + + diff --git a/example-http-stream/src/ofApp.h b/example-http-stream/src/ofApp.h new file mode 100755 index 0000000..6be69d1 --- /dev/null +++ b/example-http-stream/src/ofApp.h @@ -0,0 +1,17 @@ +#pragma once + +#include "ofMain.h" +#include "ofxOMXPlayer.h" + +class ofApp : public ofBaseApp{ + + public: + + void setup(); + void update(); + void draw(); + + ofxOMXPlayer omxPlayer; + +}; + diff --git a/src/OMXReader.cpp b/src/OMXReader.cpp index f909556..92dce40 100755 --- a/src/OMXReader.cpp +++ b/src/OMXReader.cpp @@ -8,6 +8,7 @@ OMXReader::OMXReader() { isOpen = false; + isStream = false; fileName = ""; isMatroska = false; isAVI = false; @@ -92,12 +93,18 @@ bool OMXReader::open(std::string filename, bool doSkipAvProbe) if(fileName.substr(0, 8) == "shout://" ) fileName.replace(0, 8, "http://"); - if(fileName.substr(0,6) == "mms://" || fileName.substr(0,7) == "mmsh://" || fileName.substr(0,7) == "mmst://" || fileName.substr(0,7) == "mmsu://" || - fileName.substr(0,7) == "http://" || - fileName.substr(0,7) == "rtmp://" || fileName.substr(0,6) == "udp://" || + if(fileName.substr(0,6) == "mms://" || + fileName.substr(0,7) == "mmsh://" || + fileName.substr(0,7) == "mmst://" || + fileName.substr(0,7) == "mmsu://" || + fileName.substr(0,7) == "http://" || + fileName.substr(0,8) == "https://" || + fileName.substr(0,7) == "rtmp://" || + fileName.substr(0,6) == "udp://" || fileName.substr(0,7) == "rtsp://" ) { doSkipAvProbe = false; + isStream = true; // ffmpeg dislikes the useragent from AirPlay urls //int idx = fileName.Find("|User-Agent=AppleCoreMedia"); size_t idx = fileName.find("|"); @@ -106,7 +113,7 @@ bool OMXReader::open(std::string filename, bool doSkipAvProbe) AVDictionary *d = NULL; // Enable seeking if http - if(fileName.substr(0,7) == "http://") + if(fileName.substr(0,7) == "http://" || fileName.substr(0,8) == "https://") { av_dict_set(&d, "seekable", "1", 0); } @@ -116,7 +123,7 @@ bool OMXReader::open(std::string filename, bool doSkipAvProbe) if(av_dict_count(d) == 0) { ofLog(OF_LOG_VERBOSE, "OMXReader::OpenFile - avformat_open_input enabled SEEKING "); - if(fileName.substr(0,7) == "http://") + if(fileName.substr(0,7) == "http://" || fileName.substr(0,8) == "https://") avFormatContext->pb->seekable = AVIO_SEEKABLE_NORMAL; } av_dict_free(&d); @@ -129,6 +136,7 @@ bool OMXReader::open(std::string filename, bool doSkipAvProbe) } else { + isStream = false; fileObject = new File(); if (!fileObject->open(fileName, flags)) @@ -366,7 +374,11 @@ bool OMXReader::SeekTime(int time, bool backwords, double *startpts, bool doLoop updateCurrentPTS(); }else { //ofLogVerbose(__func__) << "av_seek_frame returned >= 0, no updateCurrentPTS" << ret; - fileObject->rewindFile(); + if(fileObject) + { + fileObject->rewindFile(); + } + } diff --git a/src/OMXReader.h b/src/OMXReader.h index 70347c0..84b8f68 100755 --- a/src/OMXReader.h +++ b/src/OMXReader.h @@ -157,7 +157,6 @@ class OMXReader bool canSeek(); bool wasFileRewound; -protected: int videoIndex; int audioIndex; int subtitleIndex; @@ -182,5 +181,6 @@ class OMXReader void lock(); void unlock(); bool setActiveStreamInternal(OMXStreamType type, unsigned int index); + bool isStream; }; diff --git a/src/ofxOMXPlayer.cpp b/src/ofxOMXPlayer.cpp index 173774e..ec7bfb4 100755 --- a/src/ofxOMXPlayer.cpp +++ b/src/ofxOMXPlayer.cpp @@ -784,6 +784,11 @@ void ofxOMXPlayer::updateCurrentFrame() void ofxOMXPlayer::onUpdate(ofEventArgs& args) { + if(engine && engine->doRestart) + { + doRestart = true; + engine->doRestart = false; + } if (doRestart) { ofxOMXPlayerSettings currentSettings = getSettings(); diff --git a/src/ofxOMXPlayerEngine.cpp b/src/ofxOMXPlayerEngine.cpp index d9a33cf..a860a5c 100755 --- a/src/ofxOMXPlayerEngine.cpp +++ b/src/ofxOMXPlayerEngine.cpp @@ -41,6 +41,7 @@ ofxOMXPlayerEngine::ofxOMXPlayerEngine() doSeek = false; eglImage = NULL; + doRestart = false; } @@ -313,36 +314,43 @@ void ofxOMXPlayerEngine::process() if (isCacheEmpty) { - omxReader.SeekTime(0 * 1000.0f, AVSEEK_FLAG_BACKWARD, &startpts); - - packet = omxReader.Read(); - - if(hasAudio) + if(omxReader.isStream) { - loop_offset = audioPlayer->getCurrentPTS(); - } - else - { - if(hasVideo) - { - loop_offset = videoPlayer->getCurrentPTS(); - } - } - if (previousLoopOffset != loop_offset) + doRestart = true; + }else { + omxReader.SeekTime(0 * 1000.0f, AVSEEK_FLAG_BACKWARD, &startpts); - previousLoopOffset = loop_offset; - loopCounter++; - ofLog(OF_LOG_VERBOSE, "Loop offset : %8.02f\n", loop_offset / DVD_TIME_BASE); - - onVideoLoop(); + packet = omxReader.Read(); + if(hasAudio) + { + loop_offset = audioPlayer->getCurrentPTS(); + } + else + { + if(hasVideo) + { + loop_offset = videoPlayer->getCurrentPTS(); + } + } + if (previousLoopOffset != loop_offset) + { + + previousLoopOffset = loop_offset; + loopCounter++; + ofLog(OF_LOG_VERBOSE, "Loop offset : %8.02f\n", loop_offset / DVD_TIME_BASE); + + onVideoLoop(); + + } + if (omxReader.wasFileRewound) + { + omxReader.wasFileRewound = false; + onVideoLoop(); + } } - if (omxReader.wasFileRewound) - { - omxReader.wasFileRewound = false; - onVideoLoop(); - } + } else diff --git a/src/ofxOMXPlayerEngine.h b/src/ofxOMXPlayerEngine.h index 74c341b..8c5ec45 100755 --- a/src/ofxOMXPlayerEngine.h +++ b/src/ofxOMXPlayerEngine.h @@ -101,6 +101,7 @@ class ofxOMXPlayerEngine: public OMXThread { return doLooping; } + bool doRestart; private: