00001 #ifndef NUPPELVIDEORECORDER
00002 #define NUPPELVIDEORECORDER
00003
00004
00005 #include <sys/time.h>
00006 #include <time.h>
00007 #include <pthread.h>
00008 #ifdef MMX
00009 #undef MMX
00010 #define MMXBLAH
00011 #endif
00012 #include <lame/lame.h>
00013 #ifdef MMXBLAH
00014 #define MMX
00015 #endif
00016
00017 #include "filter.h"
00018 #include "minilzo.h"
00019 #undef HAVE_AV_CONFIG_H
00020 extern "C" {
00021 #include "../libavcodec/avcodec.h"
00022 }
00023
00024
00025 #include <vector>
00026 using namespace std;
00027
00028
00029 #include <qstring.h>
00030 #include <qmap.h>
00031
00032
00033 #include "recorderbase.h"
00034 #include "format.h"
00035 #include "cc608decoder.h"
00036
00037 #include "mythexp.h"
00038
00039 struct video_audio;
00040 struct VBIData;
00041 struct cc;
00042 class RTjpeg;
00043 class RingBuffer;
00044 class ChannelBase;
00045 class FilterManager;
00046 class FilterChain;
00047
00048 class MPUBLIC NuppelVideoRecorder : public RecorderBase, public CC608Reader
00049 {
00050 public:
00051 NuppelVideoRecorder(TVRec *rec, ChannelBase *channel);
00052 ~NuppelVideoRecorder();
00053
00054 void SetOption(const QString &name, int value);
00055 void SetOption(const QString &name, const QString &value)
00056 { RecorderBase::SetOption(name, value); }
00057
00058 void SetOptionsFromProfile(RecordingProfile *profile,
00059 const QString &videodev,
00060 const QString &audiodev,
00061 const QString &vbidev);
00062
00063 void Initialize(void);
00064 void StartRecording(void);
00065 void StopRecording(void);
00066
00067 void Pause(bool clear = true);
00068 void Unpause(void);
00069 bool IsPaused(void) const;
00070
00071 bool IsRecording(void);
00072 bool IsErrored(void);
00073
00074 long long GetFramesWritten(void);
00075
00076 bool Open(void);
00077 int GetVideoFd(void);
00078 void Reset(void);
00079
00080 void SetVideoFilters(QString &filters);
00081 void SetTranscoding(bool value) { transcoding = value; };
00082
00083 long long GetKeyframePosition(long long desired);
00084
00085 void SetNextRecording(const ProgramInfo*, RingBuffer*);
00086 void ResetForNewFile(void);
00087 void FinishRecording(void);
00088 void StartNewFile(void);
00089
00090
00091 void StreamAllocate(void);
00092 void WriteHeader(void);
00093 void WriteSeekTable(void);
00094 void WriteKeyFrameAdjustTable(QPtrList<struct kfatable_entry> *kfa_table);
00095 void UpdateSeekTable(int frame_num, long offset = 0);
00096
00097 bool SetupAVCodecVideo(void);
00098 void SetupRTjpeg(void);
00099 int AudioInit(bool skipdevice = false);
00100 void SetVideoAspect(float newAspect) {video_aspect = newAspect; };
00101 void WriteVideo(VideoFrame *frame, bool skipsync = false,
00102 bool forcekey = false);
00103 void WriteAudio(unsigned char *buf, int fnum, int timecode);
00104 void WriteText(unsigned char *buf, int len, int timecode, int pagenr);
00105
00106 void SetNewVideoParams(double newaspect);
00107
00108 protected:
00109 static void *WriteThread(void *param);
00110 static void *AudioThread(void *param);
00111 static void *VbiThread(void *param);
00112
00113 void doWriteThread(void);
00114 void doAudioThread(void);
00115 void doVbiThread(void);
00116
00117 private:
00118 inline void WriteFrameheader(rtframeheader *fh);
00119
00120 void WriteFileHeader(void);
00121
00122 void InitBuffers(void);
00123 void InitFilters(void);
00124 void ResizeVideoBuffers(void);
00125
00126 bool MJPEGInit(void);
00127
00128 int SpawnChildren(void);
00129 void KillChildren(void);
00130
00131 void BufferIt(unsigned char *buf, int len = -1, bool forcekey = false);
00132
00133 int CreateNuppelFile(void);
00134
00135 void DoV4L2(void);
00136 void DoMJPEG(void);
00137
00138 void FormatTeletextSubtitles(struct VBIData *vbidata);
00139 void FormatCC(struct cc *cc);
00140 void AddTextData(unsigned char *buf, int len,
00141 long long timecode, char type);
00142
00143 bool encoding;
00144
00145 int fd;
00146 signed char *strm;
00147 unsigned int lf, tf;
00148 int M1, M2, Q;
00149 int w, h;
00150 int pip_mode;
00151 int pid, pid2;
00152 int inputchannel;
00153 int compression;
00154 int compressaudio;
00155 unsigned long long audiobytes;
00156 int audio_channels;
00157 int audio_bits;
00158 int audio_bytes_per_sample;
00159 int audio_samplerate;
00160 int effectivedsp;
00161
00162 int usebttv;
00163 float video_aspect;
00164
00165 bool transcoding;
00166
00167 int mp3quality;
00168 char *mp3buf;
00169 int mp3buf_size;
00170 lame_global_flags *gf;
00171
00172 RTjpeg *rtjc;
00173
00174 #define OUT_LEN (1024*1024 + 1024*1024 / 64 + 16 + 3)
00175 lzo_byte out[OUT_LEN];
00176 #define HEAP_ALLOC(var,size) \
00177 long __LZO_MMODEL var [ ((size) + (sizeof(long) - 1)) / sizeof(long) ]
00178 HEAP_ALLOC(wrkmem, LZO1X_1_MEM_COMPRESS);
00179
00180 vector<struct vidbuffertype *> videobuffer;
00181 vector<struct audbuffertype *> audiobuffer;
00182 vector<struct txtbuffertype *> textbuffer;
00183
00184 int act_video_encode;
00185 int act_video_buffer;
00186
00187 int act_audio_encode;
00188 int act_audio_buffer;
00189 long long act_audio_sample;
00190
00191 int act_text_encode;
00192 int act_text_buffer;
00193
00194 int video_buffer_count;
00195 int audio_buffer_count;
00196 int text_buffer_count;
00197
00198 long video_buffer_size;
00199 long audio_buffer_size;
00200 long text_buffer_size;
00201
00202 struct timeval stm;
00203 struct timezone tzone;
00204
00205 bool childrenLive;
00206
00207 pthread_t write_tid;
00208 pthread_t audio_tid;
00209 pthread_t vbi_tid;
00210
00211 bool recording;
00212 bool errored;
00213
00214 int keyframedist;
00215 vector<struct seektable_entry> *seektable;
00216 long long lastPositionMapPos;
00217
00218 long long extendeddataOffset;
00219
00220 long long framesWritten;
00221
00222 bool livetv;
00223 bool writepaused;
00224 bool audiopaused;
00225 bool mainpaused;
00226
00227 double framerate_multiplier;
00228 double height_multiplier;
00229
00230 int last_block;
00231 int firsttc;
00232 long int oldtc;
00233 int startnum;
00234 int frameofgop;
00235 int lasttimecode;
00236 int audio_behind;
00237
00238 bool useavcodec;
00239
00240 AVCodec *mpa_vidcodec;
00241 AVCodecContext *mpa_vidctx;
00242 AVFrame mpa_picture;
00243
00244 int targetbitrate;
00245 int scalebitrate;
00246 int maxquality;
00247 int minquality;
00248 int qualdiff;
00249 int mp4opts;
00250 int mb_decision;
00252 int encoding_thread_count;
00253
00254 QString videoFilterList;
00255 FilterChain *videoFilters;
00256 FilterManager *FiltMan;
00257
00258 VideoFrameType inpixfmt;
00259 PixelFormat picture_format;
00260 int w_out;
00261 int h_out;
00262
00263 bool hardware_encode;
00264 int hmjpg_quality;
00265 int hmjpg_hdecimation;
00266 int hmjpg_vdecimation;
00267 int hmjpg_maxw;
00268
00269 bool cleartimeonpause;
00270
00271 bool usingv4l2;
00272 int channelfd;
00273
00274 long long prev_bframe_save_pos;
00275
00276 ChannelBase *channelObj;
00277
00278 bool skip_btaudio;
00279
00280 bool correct_bttv;
00281
00282 int volume;
00283
00284 CC608Decoder *ccd;
00285
00286 bool go7007;
00287 bool resetcapture;
00288 };
00289
00290 #endif