Debian Codegraph @

src/stream.h

raw
1 /* dvbcut
2 Copyright (c) 2005 Sven Over <[email protected]>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 /* $Id$ */
20
21 #ifndef DVBCUT_STREAM_H
22 #define DVBCUT_STREAM_H
23
24 #include <string>
25
26 extern "C" {
27 #include <libavcodec/avcodec.h>
28 #include <libavutil/opt.h>
29 #include <libavutil/mem.h>
30 }
31
32 class stream
33 {
34 protected:
35 int id; //avfid;
36 streamtype::type type;
37 std::string infostring;
38 const AVCodec *dec;
39 const AVCodec *enc;
40 AVCodecContext *avcc;
41 stream() : id(-1),type(streamtype::unknown),dec(0),enc(0),avcc(0)
42 {}
43 ~stream()
44 {
45 if (avcc)
46 av_free(avcc);
47 }
48 void freeavcc()
49 {
50 if (avcc)
51 av_free(avcc);
52 avcc=0;
53 }
54 void allocavcc()
55 {
56 if (avcc)
57 av_free(avcc);
58 avcc=avcodec_alloc_context3(NULL);
59 }
60 void setvideoencodingparameters(int tb_num, int tb_den, bool interlaced=false)
61 {
62 avcc->bit_rate=9500000;
63 avcc->rc_min_rate=9500000;
64 avcc->rc_max_rate=9500000;
65 avcc->rc_buffer_size=224*1024*8;
66 avcc->rc_initial_buffer_occupancy = avcc->rc_buffer_size*3/4;
67 avcc->qmax=2;
68 avcc->mb_lmax= FF_QP2LAMBDA * 2;
69 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 0, 0)
70 av_opt_set_double(avcc, "rc_buffer_aggressivity", 1.0, AV_OPT_SEARCH_CHILDREN);
71 av_opt_set_int(avcc, "lmax", FF_QP2LAMBDA * 2, AV_OPT_SEARCH_CHILDREN);
72 #else
73 avcc->rc_buffer_aggressivity=1.0;
74 avcc->lmax= FF_QP2LAMBDA * 2;
75 #endif
76 if (interlaced)
77 avcc->flags |= AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME;
78 avcc->time_base.num = tb_num;
79 avcc->time_base.den = tb_den;
80 //fprintf(stderr, "video %stb=%d/%d\n", (interlaced ? "interlaced " : ""), avcc->time_base.num, avcc->time_base.den);
81 }
82
83 friend class mpgfile;
84 friend class tsfile;
85 friend class psfile;
86 public:
87 const std::string &getinfo() const
88 {
89 return infostring;
90 }
91 };
92
93 #endif