video_record_repeat.cpp
Go to the documentation of this file.
00001 #include <pangolin/video_record_repeat.h>
00002 #include <pangolin/video/pvn_video.h>
00003 #include <pangolin/widgets.h>
00004 
00005 namespace pangolin
00006 {
00007 
00008 VideoRecordRepeat::VideoRecordRepeat(
00009     std::string uri, std::string save_filename, int buffer_size_bytes
00010 ) : video_src(0), video_file(0), video_recorder(0),
00011     filename(save_filename), buffer_size_bytes(buffer_size_bytes), frame_num(0)
00012 {
00013     video_src = OpenVideo(uri);
00014 }
00015 
00016 VideoRecordRepeat::~VideoRecordRepeat()
00017 {
00018     if(video_recorder)
00019         delete video_recorder;
00020     if( video_src )
00021         delete video_src;
00022     if( video_file )
00023         delete video_file;
00024 }
00025 
00026 void VideoRecordRepeat::Record()
00027 {
00028     if( video_recorder )
00029     {
00030         video_src->Stop();
00031         delete video_recorder;
00032         video_recorder = 0;
00033     }
00034 
00035     if(video_file)
00036     {
00037         delete video_file;
00038         video_file = 0;
00039     }
00040 
00041     video_recorder = new VideoRecorder(
00042         filename, video_src->Width(), video_src->Height(),
00043         video_src->PixFormat(), buffer_size_bytes
00044     );
00045 
00046     video_src->Start();
00047     frame_num = 0;
00048 }
00049 
00050 void VideoRecordRepeat::Play(bool realtime)
00051 {
00052     if( video_file )
00053     {
00054         delete video_file;
00055         video_file = 0;
00056     }
00057 
00058     video_src->Stop();
00059 
00060     if(video_recorder)
00061     {
00062         delete video_recorder;
00063         video_recorder = 0;
00064     }
00065 
00066     video_file = new PvnVideo(filename.c_str(),realtime);
00067     frame_num = 0;
00068 }
00069 
00070 void VideoRecordRepeat::Source()
00071 {
00072     if(video_file)
00073     {
00074         delete video_file;
00075         video_file = 0;
00076     }
00077 
00078     if(video_recorder)
00079     {
00080         delete video_recorder;
00081         video_recorder = 0;
00082     }
00083 
00084     video_src->Start();
00085     frame_num = 0;
00086 }
00087 
00088 unsigned VideoRecordRepeat::Width() const
00089 {
00090     if( !video_src ) throw VideoException("No video source open");
00091     return video_src->Width();
00092 
00093 }
00094 
00095 unsigned VideoRecordRepeat::Height() const
00096 {
00097     if( !video_src ) throw VideoException("No video source open");
00098     return video_src->Height();
00099 }
00100 
00101 size_t VideoRecordRepeat::SizeBytes() const
00102 {
00103     if( !video_src ) throw VideoException("No video source open");
00104     return video_src->SizeBytes();
00105 }
00106 
00107 std::string VideoRecordRepeat::PixFormat() const
00108 {
00109     if( !video_src ) throw VideoException("No video source open");
00110     return video_src->PixFormat();
00111 }
00112 
00113 void VideoRecordRepeat::Start()
00114 {
00115     // Semantics of this?
00116 //    video_src->Start();
00117 }
00118 
00119 void VideoRecordRepeat::Stop()
00120 {
00121     // Semantics of this?
00122     if(video_recorder)
00123     {
00124         delete video_recorder;
00125         video_recorder = 0;
00126     }
00127 }
00128 
00129 bool VideoRecordRepeat::GrabNext( unsigned char* image, bool wait )
00130 {
00131     frame_num++;
00132 
00133     if( video_recorder != 0 )
00134     {
00135         bool success = video_src->GrabNext(image,wait);
00136         if( success )
00137         {
00138             video_recorder->RecordFrame(image);
00139         }
00140         return success;
00141     }
00142     else if( video_file != 0 )
00143     {
00144         return video_file->GrabNext(image,wait);
00145     }
00146     else
00147     {
00148         return video_src->GrabNext(image,wait);
00149     }
00150 }
00151 
00152 bool VideoRecordRepeat::GrabNewest( unsigned char* image, bool wait )
00153 {
00154     frame_num++;
00155 
00156     if( video_recorder != 0 )
00157     {
00158         bool success = video_src->GrabNewest(image,wait);
00159         if( success )
00160         {
00161             video_recorder->RecordFrame(image);
00162         }
00163         return success;
00164     }
00165     else if( video_file != 0 )
00166     {
00167         return video_file->GrabNewest(image,wait);
00168     }
00169     else
00170     {
00171         return video_src->GrabNewest(image,wait);
00172     }
00173 }
00174 
00175 int VideoRecordRepeat::FrameId()
00176 {
00177     return frame_num;
00178 }
00179 
00180 bool VideoRecordRepeat::IsRecording() const
00181 {
00182     return video_recorder != 0;
00183 }
00184 
00185 bool VideoRecordRepeat::IsPlaying() const
00186 {
00187     return video_file != 0;
00188 }
00189 
00190 
00191 
00192 }
00193 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


pangolin_wrapper
Author(s): Todor Stoyanov
autogenerated on Wed Feb 13 2013 14:03:25