| | 13 | class FormatContextPtr |
| | 14 | { |
| | 15 | public: |
| | 16 | |
| | 17 | typedef AVFormatContext T; |
| | 18 | |
| | 19 | explicit FormatContextPtr() : _ptr(0) {} |
| | 20 | explicit FormatContextPtr(T* ptr) : _ptr(ptr) {} |
| | 21 | |
| | 22 | ~FormatContextPtr() |
| | 23 | { |
| | 24 | cleanup(); |
| | 25 | } |
| | 26 | |
| | 27 | T* get() { return _ptr; } |
| | 28 | |
| | 29 | T * operator-> () const // never throws |
| | 30 | { |
| | 31 | return _ptr; |
| | 32 | } |
| | 33 | |
| | 34 | void reset(T* ptr) |
| | 35 | { |
| | 36 | if (ptr==_ptr) return; |
| | 37 | cleanup(); |
| | 38 | _ptr = ptr; |
| | 39 | } |
| | 40 | |
| | 41 | void cleanup() |
| | 42 | { |
| | 43 | if (_ptr) |
| | 44 | { |
| | 45 | osg::notify(osg::NOTICE)<<"Calling av_close_input_file("<<_ptr<<")"<<std::endl; |
| | 46 | av_close_input_file(_ptr); |
| | 47 | } |
| | 48 | _ptr = 0; |
| | 49 | } |
| | 50 | |
| | 51 | |
| | 52 | |
| | 53 | protected: |
| | 54 | |
| | 55 | T* _ptr; |
| | 56 | }; |