]> rtime.felk.cvut.cz Git - frescor/streamer.git/blob - output.c
Export fps for rt_qosmgr.c (so that it can correctly set server period, etc...)
[frescor/streamer.git] / output.c
1 #include "libavformat/avformat.h"
2
3
4 AVFormatContext *open_output_stream(const char *dst, int port, enum CodecType codec_type)
5 {
6     AVFormatContext *s;
7     static AVOutputFormat *rtp_format;
8     AVStream *st;
9
10     s = av_alloc_format_context();
11     rtp_format = guess_format("rtp", NULL, NULL);
12     if (!rtp_format) {
13         fprintf(stderr, "Unable for find the RTP format for output\n");
14
15         return NULL;
16     }
17
18     s->oformat = rtp_format;
19     st = av_new_stream(s, 0);
20     if (!st) {
21         fprintf(stderr, "Cannot allocate stream\n");
22
23         return NULL;
24     }
25
26     snprintf(s->filename, sizeof(s->filename), "rtp://%s:%d", dst, port);
27         
28     /* open the UDP sockets for RTP and RTCP */
29     if (url_fopen(&s->pb, s->filename, URL_WRONLY) < 0) {
30         fprintf(stderr, "Cannot open '%s'\n", s->filename);
31         /* FIXME: Free the stream! */
32
33         return NULL;
34     }
35     avcodec_get_context_defaults2(s->streams[0]->codec, codec_type);
36     s->streams[0]->codec->codec_id = av_guess_codec(s->oformat, NULL, s->filename, NULL, codec_type);
37     s->streams[0]->codec->codec_id = CODEC_ID_MPEG4;
38     s->streams[0]->codec->pix_fmt  = PIX_FMT_YUV420P;
39     s->streams[0]->codec->mb_decision = 2;
40     s->streams[0]->codec->me_cmp = 2;
41     //s->streams[0]->codec->me_sub_cmp = 6;
42     s->streams[0]->codec->trellis = 1;
43
44     return s;
45 }
46
47 int pkt_send(AVFormatContext *ctx, AVPacket *pkt)
48 {
49   static int inited;            /* FIXME: HACK! */
50
51
52   if (!inited) {
53     int res;
54
55 fprintf(stderr,"initing!\n");
56     res = av_write_header(ctx);
57     if (res < 0) {
58       fprintf(stderr, "Cannot open the out RTP stream!\n");
59
60       return res;
61     }
62     inited = 1;
63   }
64
65   return av_write_frame(ctx, pkt);
66 }
67