Advertisement
Guest User

ofApp.cpp

a guest
Feb 23rd, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. #include "ofApp.h"
  2. #define PORT_GST 5000
  3.  
  4. //This app is a demo of the ability to play multiple files with the Non-Texture Player
  5. //It requires multiple video files to be in /home/pi/videos/current
  6. //There is a bit of glitching while the files switch
  7.  
  8. //This also demonstrates the ofxOMXPlayerListener pattern available
  9.  
  10. //If your app extends ofxOMXPlayerListener you will receive an event when the video ends
  11.  
  12.  
  13.  
  14.  
  15.  
  16. bool doLoadNextMovie = false;
  17. void ofApp::onVideoEnd(ofxOMXPlayerListenerEventData& e)
  18. {
  19. ofLogVerbose(__func__) << " RECEIVED";
  20. doLoadNextMovie = true;
  21. }
  22.  
  23.  
  24. void ofApp::onCharacterReceived(KeyListenerEventData& e)
  25. {
  26. keyPressed((int)e.character);
  27. }
  28.  
  29. unsigned long long skipTimeStart=0;
  30. unsigned long long skipTimeEnd=0;
  31. unsigned long long amountSkipped =0;
  32. unsigned long long totalAmountSkipped =0;
  33. //--------------------------------------------------------------
  34. void ofApp::setup()
  35. {
  36. ofSetLogLevel(OF_LOG_VERBOSE);
  37.  
  38. ofBackground(ofColor::black);
  39. consoleListener.setup(this);
  40.  
  41. //this will let us just grab a video without recompiling
  42. ofDirectory currentVideoDirectory(ofToDataPath("/home/pi/openFrameworks/apps/myApps/video", true));
  43. if (currentVideoDirectory.exists())
  44. {
  45. currentVideoDirectory.listDir();
  46. currentVideoDirectory.sort();
  47. files = currentVideoDirectory.getFiles();
  48. if (files.size()>0)
  49. {
  50. videoCounter = 0;
  51. settings.videoPath = files[videoCounter].path();
  52. settings.useHDMIForAudio = true; //default true
  53. settings.enableLooping = false; //default true
  54. settings.enableTexture = true; //default true
  55. settings.listener = this; //this app extends ofxOMXPlayerListener so it will receive events ;
  56. omxPlayer.setup(settings);
  57. }
  58. }
  59.  
  60. //from gstreamTest: //////////
  61.  
  62. w=1280,h=720;
  63. ip="10.254.32.151";
  64. gst.setPipeline("tcpclientsrc host="+ip+" port="+ofToString(PORT_GST)+" ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert", OF_PIXELS_RGB, true, w, h);
  65. gst.startPipeline();
  66. tex.allocate(w,h,GL_RGB);
  67. gst.play();
  68.  
  69. /////////////////////////////
  70. }
  71.  
  72.  
  73. void ofApp::loadNextMovie()
  74. {
  75. if(videoCounter+1<files.size())
  76. {
  77. videoCounter++;
  78. }else
  79. {
  80. videoCounter = 0;
  81. }
  82. skipTimeStart = ofGetElapsedTimeMillis();
  83. omxPlayer.loadMovie(files[videoCounter].path());
  84. skipTimeEnd = ofGetElapsedTimeMillis();
  85. amountSkipped = skipTimeEnd-skipTimeStart;
  86. totalAmountSkipped+=amountSkipped;
  87. doLoadNextMovie = false;
  88. }
  89.  
  90. //--------------------------------------------------------------
  91. void ofApp::update()
  92. {
  93. if (doLoadNextMovie)
  94. {
  95. ofLogVerbose(__func__) << "doing reload";
  96.  
  97. if(omxPlayer.isTextureEnabled())
  98. {
  99. //clear the texture if you want
  100. //omxPlayer.getTextureReference().clear();
  101. }
  102. //with the texture based player this must be done here - especially if the videos are different resolutions
  103. loadNextMovie();
  104. }
  105.  
  106. //from gstreamTest///////////////////////////////
  107.  
  108. gst.update();
  109. if(gst.isFrameNew()) {
  110. tex.loadData(gst.getPixels());
  111. }
  112.  
  113. /////////////////////////////////////////////////
  114.  
  115.  
  116.  
  117. }
  118.  
  119.  
  120. //--------------------------------------------------------------
  121. void ofApp::draw(){
  122.  
  123. //ofBackgroundGradient(ofColor::red, ofColor::black, OF_GRADIENT_CIRCULAR);
  124.  
  125. if(!omxPlayer.isTextureEnabled()) return;
  126.  
  127. omxPlayer.draw(0, 0, ofGetWidth(), ofGetHeight());
  128.  
  129. //from gstreamTest///////////
  130.  
  131. tex.draw(x,y,w,h);
  132.  
  133. /////////////////////////////
  134.  
  135. }
  136.  
  137. //--------------------------------------------------------------
  138. void ofApp::keyPressed (int key){
  139.  
  140. ofLogVerbose(__func__) << "key: " << key;
  141. switch (key)
  142. {
  143. case 'n':
  144. {
  145. doLoadNextMovie = true;
  146. break;
  147. }
  148. }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement