Changeset 13173
- Timestamp:
- 05/24/13 19:16:57 (6 hours ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 10 modified
-
include/osg/ImageStream (modified) (2 diffs)
-
src/osgPlugins/QTKit/OSXCoreVideoTexture.cpp (modified) (1 diff)
-
src/osgPlugins/QTKit/OSXQTKitVideo.h (modified) (1 diff)
-
src/osgPlugins/QTKit/OSXQTKitVideo.mm (modified) (5 diffs)
-
src/osgPlugins/QTKit/ReaderWriterQTKit.cpp (modified) (2 diffs)
-
src/osgPlugins/avfoundation/OSXAVFoundationVideo.h (modified) (2 diffs)
-
src/osgPlugins/avfoundation/OSXAVFoundationVideo.mm (modified) (14 diffs)
-
src/osgPlugins/avfoundation/ReaderWriterAVFoundation.cpp (modified) (2 diffs)
-
src/osgPlugins/imageio/ReaderWriterImageIO.cpp (modified) (1 diff)
-
src/osgPresentation/SlideShowConstructor.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osg/ImageStream
r13155 r13173 19 19 20 20 namespace osg { 21 22 // forward declare of osg::Texture 23 class Texture; 21 24 22 25 /** … … 99 102 AudioStreams& getAudioStreams() { return _audioStreams; } 100 103 const AudioStreams& getAudioStreams() const { return _audioStreams; } 101 102 104 105 /** create a suitable texture for this imagestream, return NULL, if not supported 106 * implement this method in subclasses to use special technologies like CoreVideo 107 * or similar. 108 */ 109 virtual osg::Texture* createSuitableTexture() { return NULL; } 110 103 111 protected: 104 112 virtual void applyLoopingMode() {} -
OpenSceneGraph/trunk/src/osgPlugins/QTKit/OSXCoreVideoTexture.cpp
r13155 r13173 139 139 _adapter = new OSXCoreVideoAdapter(state, _image.get()); 140 140 } 141 141 142 _adapter->getFrame(); 142 143 _textureTarget = _adapter->getTextureTarget(); 143 144 144 glBindTexture(_textureTarget, _adapter->getTextureName()); 145 145 } -
OpenSceneGraph/trunk/src/osgPlugins/QTKit/OSXQTKitVideo.h
r13155 r13173 82 82 } 83 83 84 static void initializeQTKit(); 85 86 virtual osg::Texture* createSuitableTexture(); 87 84 88 protected: 85 89 -
OpenSceneGraph/trunk/src/osgPlugins/QTKit/OSXQTKitVideo.mm
r13155 r13173 20 20 #include "OSXQTKitVideo.h" 21 21 #include "OSXCoreVideoAdapter.h" 22 #include "OSXCoreVideoTexture.h" 22 23 23 24 namespace { … … 89 90 90 91 92 void OSXQTKitVideo::initializeQTKit() 93 { 94 static bool inited(false); 95 if (!inited) 96 { 97 inited = true; 98 // force initialization of QTKit on the main-thread! 99 if (![NSThread isMainThread]) { 100 dispatch_apply(1, dispatch_get_main_queue(), ^(size_t n) { 101 EnterMovies(); 102 QTMovie* movie = [QTMovie movie]; 103 // release missing by intent, gets released by the block! 104 }); 105 } 106 else 107 { 108 EnterMovies(); 109 QTMovie* movie = [QTMovie movie]; 110 [movie release]; 111 } 112 } 113 } 114 91 115 92 116 OSXQTKitVideo::OSXQTKitVideo() … … 95 119 , _coreVideoAdapter(NULL) 96 120 { 121 initializeQTKit(); 122 97 123 _status = INVALID; 98 124 _data = new Data(); … … 212 238 applyLoopingMode(); 213 239 214 _waitForFirstFrame = true;240 _waitForFirstFrame = true; 215 241 requestNewFrame(true); 216 242 _fileName = file_name; 217 243 _status = (valid) ? PAUSED : INVALID; 218 244 } … … 368 394 } 369 395 } 370 396 397 398 osg::Texture* OSXQTKitVideo::createSuitableTexture() 399 { 400 return new OSXCoreVideoTexture(this); 401 } -
OpenSceneGraph/trunk/src/osgPlugins/QTKit/ReaderWriterQTKit.cpp
r13155 r13173 68 68 supportsOption("disableCoreVideo", "disable the usage of coreVideo when using readObjectFile, returns an ImageStream instead"); 69 69 supportsOption("disableMultiThreadedFrameDispatching", "disable the usage of the multithreade VideoFrameDispatcher to decode video frames"); 70 70 71 71 } 72 72 … … 95 95 if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; 96 96 } 97 98 static OpenThreads::Mutex mutex; 99 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutex); 97 100 98 101 OSG_INFO<<"ReaderWriterQTKit::readImage "<< fileName<< std::endl; -
OpenSceneGraph/trunk/src/osgPlugins/avfoundation/OSXAVFoundationVideo.h
r13155 r13173 58 58 virtual void seek(double pos); 59 59 60 virtual void rewind() { 61 seek(0); 62 } 63 60 64 61 65 /// returns the current playing position … … 92 96 void lazyInitCoreVideoTextureCache(osg::State& state); 93 97 bool getCurrentCoreVideoTexture(GLenum& target, GLint& name, int& width, int& height) const; 98 99 virtual osg::Texture* createSuitableTexture(); 100 94 101 protected: 95 102 -
OpenSceneGraph/trunk/src/osgPlugins/avfoundation/OSXAVFoundationVideo.mm
r13155 r13173 4 4 #include <osgViewer/api/Cocoa/GraphicsWindowCocoa> 5 5 #include <iostream> 6 #include <deque> 6 7 7 8 #import <AVFoundation/AVFoundation.h> 8 9 #import <Cocoa/Cocoa.h> 9 10 11 #include "OSXAVFoundationCoreVideoTexture.h" 10 12 11 13 … … 100 102 public: 101 103 AVPlayer* avplayer; 102 AVPlayerItem* avplayeritem;103 104 AVPlayerItemVideoOutput* output; 104 105 OSXAVFoundationVideoDelegate* delegate; … … 109 110 Data() 110 111 : avplayer(NULL) 111 , avplayeritem(NULL)112 112 , output(NULL) 113 113 , delegate(NULL) … … 118 118 { 119 119 } 120 121 void clear() 122 { 123 if (delegate) { 124 [[NSNotificationCenter defaultCenter] removeObserver: delegate 125 name:AVPlayerItemDidPlayToEndTimeNotification 126 object:avplayer.currentItem 127 ]; 128 [delegate release]; 129 } 130 131 if (avplayer) { 132 [avplayer cancelPendingPrerolls]; 133 [avplayer.currentItem.asset cancelLoading]; 134 [avplayer.currentItem removeOutput:output]; 135 } 136 137 [output release]; 138 [avplayer release]; 139 140 141 avplayer = NULL; 142 output = NULL; 143 delegate = NULL; 144 } 145 120 146 ~Data() { 121 [output release]; 122 [avplayeritem release]; 123 [avplayer release]; 124 125 [delegate release]; 147 148 clear(); 126 149 127 150 for(unsigned int i=0; i< lastFrames.size(); ++i) … … 138 161 coreVideoTextureCache = NULL; 139 162 } 140 output = NULL;141 avplayer = NULL;142 avplayeritem = NULL;143 delegate = NULL;144 163 } 145 164 … … 189 208 _status = INVALID; 190 209 setOrigin(TOP_LEFT); 210 211 // std::cout << " OSXAVFoundationVideo " << this << std::endl; 191 212 } 192 213 … … 194 215 OSXAVFoundationVideo::~OSXAVFoundationVideo() 195 216 { 217 // std::cout << "~OSXAVFoundationVideo " << this << " " << _data->avplayer << std::endl; 196 218 quit(); 219 clear(); 197 220 if (_data) 198 221 delete _data; … … 227 250 void OSXAVFoundationVideo::pause() 228 251 { 252 setNeedsDispatching(StopUpdate); 253 254 NSAutoreleasePoolHelper helper; 255 229 256 if (_data->avplayer) { 230 257 [_data->avplayer pause]; 231 258 _status = PAUSED; 232 setNeedsDispatching(StopUpdate);233 259 } 234 260 } … … 237 263 void OSXAVFoundationVideo::clear() 238 264 { 239 [_data->output release]; 240 [_data->avplayeritem release]; 241 [_data->avplayer release]; 242 243 if (_data->delegate) { 244 [[NSNotificationCenter defaultCenter] removeObserver: _data->delegate 245 name:AVPlayerItemDidPlayToEndTimeNotification 246 object:[_data->avplayer currentItem] 247 ]; 248 } 249 250 [_data->delegate release]; 251 252 _data->output = NULL; 253 _data->avplayer = NULL; 254 _data->avplayeritem = NULL; 255 _data->delegate = NULL; 265 if (_data) 266 _data->clear(); 256 267 } 257 268 … … 278 289 void OSXAVFoundationVideo::open(const std::string& filename) 279 290 { 291 NSAutoreleasePoolHelper helper; 292 280 293 clear(); 281 294 … … 304 317 } 305 318 306 _data->avplayeritem = [[AVPlayerItem alloc] initWithURL: url]; 307 _data->avplayer = [AVPlayer playerWithPlayerItem: _data->avplayeritem]; 319 _data->avplayer = [AVPlayer playerWithURL: url]; // AVPlayerFactory::instance()->getOrCreate(url); 320 [_data->avplayer retain]; 321 308 322 _data->avplayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; 309 323 310 [[_data->avplayer currentItem] addOutput:_data->output]; 324 [_data->avplayer.currentItem addOutput:_data->output]; 325 311 326 312 327 [[NSNotificationCenter defaultCenter] addObserver: _data->delegate 313 328 selector:@selector(playerItemDidReachEnd:) 314 329 name:AVPlayerItemDidPlayToEndTimeNotification 315 object:[_data->avplayer currentItem]]; 316 317 _videoDuration = CMTimeGetSeconds([[_data->avplayer currentItem] duration]); 330 object:_data->avplayer.currentItem]; 331 332 333 _videoDuration = CMTimeGetSeconds([_data->avplayer.currentItem duration]); 318 334 319 335 // get the max size of the video-tracks 320 NSArray* tracks = [_data->avplayer item.asset tracksWithMediaType: AVMediaTypeVideo];336 NSArray* tracks = [_data->avplayer.currentItem.asset tracksWithMediaType: AVMediaTypeVideo]; 321 337 CGSize size; 322 338 for(unsigned int i=0; i < [tracks count]; ++i) … … 330 346 _t = size.height; 331 347 _r = 1; 332 348 unsigned char* buffer = (unsigned char*)calloc(_s*_t*4, 1); 349 setImage(_s, _t, 1, GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE, buffer, USE_MALLOC_FREE); 350 351 _fileName = filename; 352 333 353 requestNewFrame(); 334 354 … … 345 365 void OSXAVFoundationVideo::setVolume(float v) 346 366 { 367 NSAutoreleasePoolHelper helper; 347 368 _volume = v; 348 369 if (_data->avplayer) … … 512 533 } 513 534 } 514 535 536 537 osg::Texture* OSXAVFoundationVideo::createSuitableTexture() 538 { 539 return NULL; // new OSXAVFoundationCoreVideoTexture(this); 540 } 541 542 -
OpenSceneGraph/trunk/src/osgPlugins/avfoundation/ReaderWriterAVFoundation.cpp
r13155 r13173 60 60 if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; 61 61 } 62 62 63 static OpenThreads::Mutex mutex; 64 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutex); 65 63 66 OSG_INFO<<"ReaderWriterAVFoundation::readImage "<< fileName<< std::endl; 64 67 … … 66 69 67 70 bool disable_multi_threaded_frame_dispatching = options ? (options->getPluginStringData("disableMultiThreadedFrameDispatching") == "true") : false; 68 bool disable_core_video = true; //options ? (options->getPluginStringData("disableCoreVideo") == "true") : false;71 bool disable_core_video = options ? (options->getPluginStringData("disableCoreVideo") == "true") : false; 69 72 OSG_INFO << "disableMultiThreadedFrameDispatching: " << disable_multi_threaded_frame_dispatching << std::endl; 70 73 OSG_INFO << "disableCoreVideo : " << disable_core_video << std::endl; -
OpenSceneGraph/trunk/src/osgPlugins/imageio/ReaderWriterImageIO.cpp
r13163 r13173 337 337 case 16: 338 338 case 32: 339 case 64: 339 340 { 340 341 -
OpenSceneGraph/trunk/src/osgPresentation/SlideShowConstructor.cpp
r13141 r13173 60 60 61 61 #define USE_CLIENT_STORAGE_HINT 0 62 #define USE_TEXTURE_FROM_VIDEO_PLUGIN 1 62 63 63 64 class SetToTransparentBin : public osg::NodeVisitor … … 771 772 { 772 773 osg::Geometry* pictureQuad = 0; 773 osg:: Texture*texture = 0;774 osg::ref_ptr<osg::Texture> texture = 0; 774 775 osg::StateSet* stateset = 0; 775 776 … … 783 784 784 785 osg::ImageStream* imageStream = dynamic_cast<osg::ImageStream*>(image); 785 786 787 // let the video-plugin create a texture for us, if supported 788 #if USE_TEXTURE_FROM_VIDEO_PLUGIN 789 if(imageStream) 790 { 791 texture = imageStream->createSuitableTexture(); 792 } 793 #endif 794 786 795 bool flipYAxis = image->getOrigin()==osg::Image::TOP_LEFT; 787 796 … … 799 808 usedTextureRectangle = useTextureRectangle; 800 809 801 if (useTextureRectangle) 802 { 810 if (!texture) 811 { 812 if (useTextureRectangle) 813 { 814 texture = new osg::TextureRectangle(image); 815 } 816 else 817 { 818 texture = new osg::Texture2D(image); 819 820 texture->setResizeNonPowerOfTwoHint(false); 821 texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); 822 texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); 823 #if USE_CLIENT_STORAGE_HINT 824 texture->setClientStorageHint(true); 825 #endif 826 827 } 828 } 829 if (texture) 830 { 831 float t(0), l(0); 832 float r = (texture->getTextureTarget() == GL_TEXTURE_RECTANGLE) ? image->s() : 1; 833 float b = (texture->getTextureTarget() == GL_TEXTURE_RECTANGLE) ? image->t() : 1; 834 835 if (flipYAxis) 836 std::swap(t,b); 837 803 838 pictureQuad = osg::createTexturedQuadGeometry(positionVec, 804 widthVec, 805 heightVec, 806 0.0f, flipYAxis ? image->t() : 0.0f, 807 image->s(), flipYAxis ? 0.0f : image->t()); 808 839 widthVec, 840 heightVec, 841 l, t, r, b); 842 809 843 stateset = pictureQuad->getOrCreateStateSet(); 810 811 texture = new osg::TextureRectangle(image);812 844 stateset->setTextureAttributeAndModes(0, 813 texture, 814 osg::StateAttribute::ON); 815 816 817 818 } 819 else 820 { 821 pictureQuad = osg::createTexturedQuadGeometry(positionVec, 822 widthVec, 823 heightVec, 824 0.0f, flipYAxis ? 1.0f : 0.0f, 825 1.0f, flipYAxis ? 0.0f : 1.0f); 826 827 stateset = pictureQuad->getOrCreateStateSet(); 828 829 texture = new osg::Texture2D(image); 830 831 texture->setResizeNonPowerOfTwoHint(false); 832 texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); 833 texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); 834 #if USE_CLIENT_STORAGE_HINT 835 texture->setClientStorageHint(true); 836 #endif 837 stateset->setTextureAttributeAndModes(0, 838 texture, 839 osg::StateAttribute::ON); 840 841 } 842 845 texture, 846 osg::StateAttribute::ON); 847 } 848 843 849 if (!pictureQuad) return 0; 844 850 845 851 if (imageStream) 846 852 {
