Skip to content

Commit

Permalink
Merge pull request #86 from jvcleave/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jvcleave authored Aug 18, 2016
2 parents bdcd67f + f0698c6 commit a295e72
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 32 deletions.
13 changes: 13 additions & 0 deletions example-http-stream/Makefile
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions example-http-stream/addons.make
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ofxOMXPlayer
8 changes: 8 additions & 0 deletions example-http-stream/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "ofMain.h"
#include "ofApp.h"

int main()
{
ofSetupOpenGL(1280, 720, OF_WINDOW);
ofRunApp( new ofApp());
}
60 changes: 60 additions & 0 deletions example-http-stream/src/ofApp.cpp
Original file line number Diff line number Diff line change
@@ -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);
}


17 changes: 17 additions & 0 deletions example-http-stream/src/ofApp.h
Original file line number Diff line number Diff line change
@@ -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;

};

24 changes: 18 additions & 6 deletions src/OMXReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
OMXReader::OMXReader()
{
isOpen = false;
isStream = false;
fileName = "";
isMatroska = false;
isAVI = false;
Expand Down Expand Up @@ -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("|");
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -129,6 +136,7 @@ bool OMXReader::open(std::string filename, bool doSkipAvProbe)
}
else
{
isStream = false;
fileObject = new File();

if (!fileObject->open(fileName, flags))
Expand Down Expand Up @@ -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();
}

}


Expand Down
2 changes: 1 addition & 1 deletion src/OMXReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ class OMXReader
bool canSeek();
bool wasFileRewound;

protected:
int videoIndex;
int audioIndex;
int subtitleIndex;
Expand All @@ -182,5 +181,6 @@ class OMXReader
void lock();
void unlock();
bool setActiveStreamInternal(OMXStreamType type, unsigned int index);
bool isStream;
};

5 changes: 5 additions & 0 deletions src/ofxOMXPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
58 changes: 33 additions & 25 deletions src/ofxOMXPlayerEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ofxOMXPlayerEngine::ofxOMXPlayerEngine()
doSeek = false;

eglImage = NULL;
doRestart = false;


}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/ofxOMXPlayerEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class ofxOMXPlayerEngine: public OMXThread
{
return doLooping;
}
bool doRestart;
private:


Expand Down

0 comments on commit a295e72

Please sign in to comment.