~ubuntu-branches/ubuntu/lucid/ffmpeg/lucid-security

« back to all changes in this revision

Viewing changes to ffserver.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-03-13 09:18:28 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090313091828-n4ktby5eca487uhv
Tags: 3:0.svn20090303-1ubuntu1+unstripped1
merge from ubuntu.jaunty branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "libavformat/avformat.h"
33
33
#include "libavformat/network.h"
34
34
#include "libavformat/os_support.h"
35
 
#include "libavformat/rtp.h"
 
35
#include "libavformat/rtpdec.h"
36
36
#include "libavformat/rtsp.h"
37
37
#include "libavutil/avstring.h"
38
38
#include "libavutil/random.h"
103
103
 
104
104
#define SYNC_TIMEOUT (10 * 1000)
105
105
 
 
106
typedef struct RTSPActionServerSetup {
 
107
    uint32_t ipaddr;
 
108
    char transport_option[512];
 
109
} RTSPActionServerSetup;
 
110
 
106
111
typedef struct {
107
112
    int64_t count1, count2;
108
113
    int64_t time1, time2;
268
273
static int rtsp_parse_request(HTTPContext *c);
269
274
static void rtsp_cmd_describe(HTTPContext *c, const char *url);
270
275
static void rtsp_cmd_options(HTTPContext *c, const char *url);
271
 
static void rtsp_cmd_setup(HTTPContext *c, const char *url, RTSPHeader *h);
272
 
static void rtsp_cmd_play(HTTPContext *c, const char *url, RTSPHeader *h);
273
 
static void rtsp_cmd_pause(HTTPContext *c, const char *url, RTSPHeader *h);
274
 
static void rtsp_cmd_teardown(HTTPContext *c, const char *url, RTSPHeader *h);
 
276
static void rtsp_cmd_setup(HTTPContext *c, const char *url, RTSPMessageHeader *h);
 
277
static void rtsp_cmd_play(HTTPContext *c, const char *url, RTSPMessageHeader *h);
 
278
static void rtsp_cmd_pause(HTTPContext *c, const char *url, RTSPMessageHeader *h);
 
279
static void rtsp_cmd_teardown(HTTPContext *c, const char *url, RTSPMessageHeader *h);
275
280
 
276
281
/* SDP handling */
277
282
static int prepare_sdp_description(FFStream *stream, uint8_t **pbuffer,
1350
1355
        }
1351
1356
    }
1352
1357
 
 
1358
    if (c->post == 0 && stream->stream_type == STREAM_TYPE_LIVE)
 
1359
        current_bandwidth += stream->bandwidth;
 
1360
 
1353
1361
    /* If already streaming this feed, do not let start another feeder. */
1354
1362
    if (stream->feed_opened) {
1355
1363
        snprintf(msg, sizeof(msg), "This feed is already being received.");
1357
1365
        goto send_error;
1358
1366
    }
1359
1367
 
1360
 
    if (c->post == 0 && stream->stream_type == STREAM_TYPE_LIVE)
1361
 
        current_bandwidth += stream->bandwidth;
1362
 
 
1363
1368
    if (c->post == 0 && max_bandwidth < current_bandwidth) {
1364
1369
        c->http_error = 200;
1365
1370
        q = c->buffer;
2038
2043
    switch(c->state) {
2039
2044
    case HTTPSTATE_SEND_DATA_HEADER:
2040
2045
        memset(&c->fmt_ctx, 0, sizeof(c->fmt_ctx));
2041
 
        av_strlcpy(c->fmt_ctx.author, c->stream->author,
2042
 
                   sizeof(c->fmt_ctx.author));
2043
 
        av_strlcpy(c->fmt_ctx.comment, c->stream->comment,
2044
 
                   sizeof(c->fmt_ctx.comment));
2045
 
        av_strlcpy(c->fmt_ctx.copyright, c->stream->copyright,
2046
 
                   sizeof(c->fmt_ctx.copyright));
2047
 
        av_strlcpy(c->fmt_ctx.title, c->stream->title,
2048
 
                   sizeof(c->fmt_ctx.title));
 
2046
        av_metadata_set(&c->fmt_ctx.metadata, "author"   ,c->stream->author);
 
2047
        av_metadata_set(&c->fmt_ctx.metadata, "comment"  ,c->stream->comment);
 
2048
        av_metadata_set(&c->fmt_ctx.metadata, "copyright",c->stream->copyright);
 
2049
        av_metadata_set(&c->fmt_ctx.metadata, "title"    ,c->stream->title);
2049
2050
 
2050
2051
        for(i=0;i<c->stream->nb_streams;i++) {
2051
2052
            AVStream *st;
2408
2409
    }
2409
2410
    c->feed_fd = fd;
2410
2411
 
2411
 
    c->stream->feed_write_index = ffm_read_write_index(fd);
 
2412
    if ((c->stream->feed_write_index = ffm_read_write_index(fd)) < 0) {
 
2413
        http_log("Error reading write index from feed file: %s\n", strerror(errno));
 
2414
        return -1;
 
2415
    }
2412
2416
    c->stream->feed_size = lseek(fd, 0, SEEK_END);
2413
2417
    lseek(fd, 0, SEEK_SET);
2414
2418
 
2474
2478
                feed->feed_write_index = FFM_PACKET_SIZE;
2475
2479
 
2476
2480
            /* write index */
2477
 
            ffm_write_write_index(c->feed_fd, feed->feed_write_index);
 
2481
            if (ffm_write_write_index(c->feed_fd, feed->feed_write_index) < 0) {
 
2482
                http_log("Error writing index to feed file: %s\n", strerror(errno));
 
2483
                goto fail;
 
2484
            }
2478
2485
 
2479
2486
            /* wake up any waiting connections */
2480
2487
            for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) {
2617
2624
    char protocol[32];
2618
2625
    char line[1024];
2619
2626
    int len;
2620
 
    RTSPHeader header1, *header = &header1;
 
2627
    RTSPMessageHeader header1, *header = &header1;
2621
2628
 
2622
2629
    c->buffer_ptr[0] = '\0';
2623
2630
    p = c->buffer;
2643
2650
    }
2644
2651
 
2645
2652
    /* parse each header line */
2646
 
    memset(header, 0, sizeof(RTSPHeader));
 
2653
    memset(header, 0, sizeof(*header));
2647
2654
    /* skip to next line */
2648
2655
    while (*p != '\n' && *p != '\0')
2649
2656
        p++;
2706
2713
    AVStream avs[MAX_STREAMS];
2707
2714
    int i;
2708
2715
 
2709
 
    avc =  av_alloc_format_context();
 
2716
    avc =  avformat_alloc_context();
2710
2717
    if (avc == NULL) {
2711
2718
        return -1;
2712
2719
    }
2713
 
    if (stream->title[0] != 0) {
2714
 
        av_strlcpy(avc->title, stream->title, sizeof(avc->title));
2715
 
    } else {
2716
 
        av_strlcpy(avc->title, "No Title", sizeof(avc->title));
2717
 
    }
 
2720
    av_metadata_set(&avc->metadata, "title",
 
2721
                    stream->title[0] ? stream->title : "No Title");
2718
2722
    avc->nb_streams = stream->nb_streams;
2719
2723
    if (stream->is_multicast) {
2720
2724
        snprintf(avc->filename, 1024, "rtp://%s:%d?multicast=1?ttl=%d",
2800
2804
    return NULL;
2801
2805
}
2802
2806
 
2803
 
static RTSPTransportField *find_transport(RTSPHeader *h, enum RTSPLowerTransport lower_transport)
 
2807
static RTSPTransportField *find_transport(RTSPMessageHeader *h, enum RTSPLowerTransport lower_transport)
2804
2808
{
2805
2809
    RTSPTransportField *th;
2806
2810
    int i;
2814
2818
}
2815
2819
 
2816
2820
static void rtsp_cmd_setup(HTTPContext *c, const char *url,
2817
 
                           RTSPHeader *h)
 
2821
                           RTSPMessageHeader *h)
2818
2822
{
2819
2823
    FFStream *stream;
2820
2824
    int stream_index, port;
2985
2989
    return NULL;
2986
2990
}
2987
2991
 
2988
 
static void rtsp_cmd_play(HTTPContext *c, const char *url, RTSPHeader *h)
 
2992
static void rtsp_cmd_play(HTTPContext *c, const char *url, RTSPMessageHeader *h)
2989
2993
{
2990
2994
    HTTPContext *rtp_c;
2991
2995
 
3019
3023
    url_fprintf(c->pb, "\r\n");
3020
3024
}
3021
3025
 
3022
 
static void rtsp_cmd_pause(HTTPContext *c, const char *url, RTSPHeader *h)
 
3026
static void rtsp_cmd_pause(HTTPContext *c, const char *url, RTSPMessageHeader *h)
3023
3027
{
3024
3028
    HTTPContext *rtp_c;
3025
3029
 
3044
3048
    url_fprintf(c->pb, "\r\n");
3045
3049
}
3046
3050
 
3047
 
static void rtsp_cmd_teardown(HTTPContext *c, const char *url, RTSPHeader *h)
 
3051
static void rtsp_cmd_teardown(HTTPContext *c, const char *url, RTSPMessageHeader *h)
3048
3052
{
3049
3053
    HTTPContext *rtp_c;
3050
3054
    char session_id[32];
3149
3153
    int max_packet_size;
3150
3154
 
3151
3155
    /* now we can open the relevant output stream */
3152
 
    ctx = av_alloc_format_context();
 
3156
    ctx = avformat_alloc_context();
3153
3157
    if (!ctx)
3154
3158
        return -1;
3155
3159
    ctx->oformat = guess_format("rtp", NULL, NULL);
4405
4409
        } else {
4406
4410
            fprintf(stderr, "%s:%d: Incorrect keyword: '%s'\n",
4407
4411
                    filename, line_num, cmd);
4408
 
            errors++;
4409
4412
        }
4410
4413
    }
4411
4414