]> rtime.felk.cvut.cz Git - frescor/streamer.git/blob - output.c
Make some parameters configurable
[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
40     return s;
41 }
42
43 int pkt_send(AVFormatContext *ctx, AVPacket *pkt)
44 {
45   static int inited;            /* FIXME: HACK! */
46
47
48   if (!inited) {
49     int res;
50
51 fprintf(stderr,"initing!\n");
52     res = av_write_header(ctx);
53     if (res < 0) {
54       fprintf(stderr, "Cannot open the out RTP stream!\n");
55
56       return res;
57     }
58     inited = 1;
59   }
60
61   return av_write_frame(ctx, pkt);
62 }
63