| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Realmedia RTSP protocol (RDT) support. | 2 * Realmedia RTSP protocol (RDT) support. |
| 3 * Copyright (c) 2007 Ronald S. Bultje | 3 * Copyright (c) 2007 Ronald S. Bultje |
| 4 * | 4 * |
| 5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
| 6 * | 6 * |
| 7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 int i; | 79 int i; |
| 80 | 80 |
| 81 for (i = 1; i < s->n_streams; i++) | 81 for (i = 1; i < s->n_streams; i++) |
| 82 s->streams[i]->priv_data = NULL; | 82 s->streams[i]->priv_data = NULL; |
| 83 | 83 |
| 84 av_free(s); | 84 av_free(s); |
| 85 } | 85 } |
| 86 | 86 |
| 87 struct PayloadContext { | 87 struct PayloadContext { |
| 88 AVFormatContext *rmctx; | 88 AVFormatContext *rmctx; |
| 89 RMStream *rmst[MAX_STREAMS]; | 89 int nb_rmst; |
| 90 RMStream **rmst; |
| 90 uint8_t *mlti_data; | 91 uint8_t *mlti_data; |
| 91 unsigned int mlti_data_size; | 92 unsigned int mlti_data_size; |
| 92 char buffer[RTP_MAX_PACKET_LENGTH + FF_INPUT_BUFFER_PADDING_SIZE]; | 93 char buffer[RTP_MAX_PACKET_LENGTH + FF_INPUT_BUFFER_PADDING_SIZE]; |
| 93 int audio_pkt_cnt; /**< remaining audio packets in rmdec */ | 94 int audio_pkt_cnt; /**< remaining audio packets in rmdec */ |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 void | 97 void |
| 97 ff_rdt_calc_response_and_checksum(char response[41], char chksum[9], | 98 ff_rdt_calc_response_and_checksum(char response[41], char chksum[9], |
| 98 const char *challenge) | 99 const char *challenge) |
| 99 { | 100 { |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 415 |
| 415 if (av_strstart(p, "OpaqueData:buffer;", &p)) { | 416 if (av_strstart(p, "OpaqueData:buffer;", &p)) { |
| 416 rdt->mlti_data = rdt_parse_b64buf(&rdt->mlti_data_size, p); | 417 rdt->mlti_data = rdt_parse_b64buf(&rdt->mlti_data_size, p); |
| 417 } else if (av_strstart(p, "StartTime:integer;", &p)) | 418 } else if (av_strstart(p, "StartTime:integer;", &p)) |
| 418 stream->first_dts = atoi(p); | 419 stream->first_dts = atoi(p); |
| 419 else if (av_strstart(p, "ASMRuleBook:string;", &p)) { | 420 else if (av_strstart(p, "ASMRuleBook:string;", &p)) { |
| 420 int n, first = -1; | 421 int n, first = -1; |
| 421 | 422 |
| 422 for (n = 0; n < s->nb_streams; n++) | 423 for (n = 0; n < s->nb_streams; n++) |
| 423 if (s->streams[n]->priv_data == stream->priv_data) { | 424 if (s->streams[n]->priv_data == stream->priv_data) { |
| 425 int count = s->streams[n]->index + 1; |
| 424 if (first == -1) first = n; | 426 if (first == -1) first = n; |
| 427 if (rdt->nb_rmst < count) { |
| 428 RMStream **rmst= av_realloc(rdt->rmst, count*sizeof(*rmst)); |
| 429 if (!rmst) |
| 430 return AVERROR(ENOMEM); |
| 431 memset(rmst + rdt->nb_rmst, 0, |
| 432 (count - rdt->nb_rmst) * sizeof(*rmst)); |
| 433 rdt->rmst = rmst; |
| 434 rdt->nb_rmst = count; |
| 435 } |
| 425 rdt->rmst[s->streams[n]->index] = ff_rm_alloc_rmstream(); | 436 rdt->rmst[s->streams[n]->index] = ff_rm_alloc_rmstream(); |
| 426 rdt_load_mdpr(rdt, s->streams[n], (n - first) * 2); | 437 rdt_load_mdpr(rdt, s->streams[n], (n - first) * 2); |
| 427 | 438 |
| 428 if (s->streams[n]->codec->codec_id == CODEC_ID_AAC) | 439 if (s->streams[n]->codec->codec_id == CODEC_ID_AAC) |
| 429 s->streams[n]->codec->frame_size = 1; // FIXME | 440 s->streams[n]->codec->frame_size = 1; // FIXME |
| 430 } | 441 } |
| 431 } | 442 } |
| 432 | 443 |
| 433 return 0; | 444 return 0; |
| 434 } | 445 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 458 st->first_dts = orig_st->first_dts; | 469 st->first_dts = orig_st->first_dts; |
| 459 | 470 |
| 460 return st; | 471 return st; |
| 461 } | 472 } |
| 462 | 473 |
| 463 static void | 474 static void |
| 464 real_parse_asm_rulebook(AVFormatContext *s, AVStream *orig_st, | 475 real_parse_asm_rulebook(AVFormatContext *s, AVStream *orig_st, |
| 465 const char *p) | 476 const char *p) |
| 466 { | 477 { |
| 467 const char *end; | 478 const char *end; |
| 468 int n_rules, odd = 0; | 479 int n_rules = 0, odd = 0; |
| 469 AVStream *st; | 480 AVStream *st; |
| 470 | 481 |
| 471 /** | 482 /** |
| 472 * The ASMRuleBook contains a list of comma-separated strings per rule, | 483 * The ASMRuleBook contains a list of comma-separated strings per rule, |
| 473 * and each rule is separated by a ;. The last one also has a ; at the | 484 * and each rule is separated by a ;. The last one also has a ; at the |
| 474 * end so we can use it as delimiter. | 485 * end so we can use it as delimiter. |
| 475 * Every rule occurs twice, once for when the RTSP packet header marker | 486 * Every rule occurs twice, once for when the RTSP packet header marker |
| 476 * is set and once for if it isn't. We only read the first because we | 487 * is set and once for if it isn't. We only read the first because we |
| 477 * don't care much (that's what the "odd" variable is for). | 488 * don't care much (that's what the "odd" variable is for). |
| 478 * Each rule contains a set of one or more statements, optionally | 489 * Each rule contains a set of one or more statements, optionally |
| 479 * preceeded by a single condition. If there's a condition, the rule | 490 * preceeded by a single condition. If there's a condition, the rule |
| 480 * starts with a '#'. Multiple conditions are merged between brackets, | 491 * starts with a '#'. Multiple conditions are merged between brackets, |
| 481 * so there are never multiple conditions spread out over separate | 492 * so there are never multiple conditions spread out over separate |
| 482 * statements. Generally, these conditions are bitrate limits (min/max) | 493 * statements. Generally, these conditions are bitrate limits (min/max) |
| 483 * for multi-bitrate streams. | 494 * for multi-bitrate streams. |
| 484 */ | 495 */ |
| 485 if (*p == '\"') p++; | 496 if (*p == '\"') p++; |
| 486 for (n_rules = 0; s->nb_streams < MAX_STREAMS;) { | 497 while (1) { |
| 487 if (!(end = strchr(p, ';'))) | 498 if (!(end = strchr(p, ';'))) |
| 488 break; | 499 break; |
| 489 if (!odd && end != p) { | 500 if (!odd && end != p) { |
| 490 if (n_rules > 0) | 501 if (n_rules > 0) |
| 491 st = add_dstream(s, orig_st); | 502 st = add_dstream(s, orig_st); |
| 492 else | 503 else |
| 493 st = orig_st; | 504 st = orig_st; |
| 505 if (!st) |
| 506 break; |
| 494 real_parse_asm_rule(st, p, end); | 507 real_parse_asm_rule(st, p, end); |
| 495 n_rules++; | 508 n_rules++; |
| 496 } | 509 } |
| 497 p = end + 1; | 510 p = end + 1; |
| 498 odd ^= 1; | 511 odd ^= 1; |
| 499 } | 512 } |
| 500 } | 513 } |
| 501 | 514 |
| 502 void | 515 void |
| 503 ff_real_parse_sdp_a_line (AVFormatContext *s, int stream_index, | 516 ff_real_parse_sdp_a_line (AVFormatContext *s, int stream_index, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 517 av_open_input_stream(&rdt->rmctx, NULL, "", &rdt_demuxer, NULL); | 530 av_open_input_stream(&rdt->rmctx, NULL, "", &rdt_demuxer, NULL); |
| 518 | 531 |
| 519 return rdt; | 532 return rdt; |
| 520 } | 533 } |
| 521 | 534 |
| 522 static void | 535 static void |
| 523 rdt_free_context (PayloadContext *rdt) | 536 rdt_free_context (PayloadContext *rdt) |
| 524 { | 537 { |
| 525 int i; | 538 int i; |
| 526 | 539 |
| 527 for (i = 0; i < MAX_STREAMS; i++) | 540 for (i = 0; i < rdt->nb_rmst; i++) |
| 528 if (rdt->rmst[i]) { | 541 if (rdt->rmst[i]) { |
| 529 ff_rm_free_rmstream(rdt->rmst[i]); | 542 ff_rm_free_rmstream(rdt->rmst[i]); |
| 530 av_freep(&rdt->rmst[i]); | 543 av_freep(&rdt->rmst[i]); |
| 531 } | 544 } |
| 532 if (rdt->rmctx) | 545 if (rdt->rmctx) |
| 533 av_close_input_stream(rdt->rmctx); | 546 av_close_input_stream(rdt->rmctx); |
| 534 av_freep(&rdt->mlti_data); | 547 av_freep(&rdt->mlti_data); |
| 548 av_freep(&rdt->rmst); |
| 535 av_free(rdt); | 549 av_free(rdt); |
| 536 } | 550 } |
| 537 | 551 |
| 538 #define RDT_HANDLER(n, s, t) \ | 552 #define RDT_HANDLER(n, s, t) \ |
| 539 static RTPDynamicProtocolHandler ff_rdt_ ## n ## _handler = { \ | 553 static RTPDynamicProtocolHandler ff_rdt_ ## n ## _handler = { \ |
| 540 .enc_name = s, \ | 554 .enc_name = s, \ |
| 541 .codec_type = t, \ | 555 .codec_type = t, \ |
| 542 .codec_id = CODEC_ID_NONE, \ | 556 .codec_id = CODEC_ID_NONE, \ |
| 543 .parse_sdp_a_line = rdt_parse_sdp_line, \ | 557 .parse_sdp_a_line = rdt_parse_sdp_line, \ |
| 544 .open = rdt_new_context, \ | 558 .open = rdt_new_context, \ |
| 545 .close = rdt_free_context, \ | 559 .close = rdt_free_context, \ |
| 546 .parse_packet = rdt_parse_packet \ | 560 .parse_packet = rdt_parse_packet \ |
| 547 }; | 561 }; |
| 548 | 562 |
| 549 RDT_HANDLER(live_video, "x-pn-multirate-realvideo-live", AVMEDIA_TYPE_VIDEO); | 563 RDT_HANDLER(live_video, "x-pn-multirate-realvideo-live", AVMEDIA_TYPE_VIDEO); |
| 550 RDT_HANDLER(live_audio, "x-pn-multirate-realaudio-live", AVMEDIA_TYPE_AUDIO); | 564 RDT_HANDLER(live_audio, "x-pn-multirate-realaudio-live", AVMEDIA_TYPE_AUDIO); |
| 551 RDT_HANDLER(video, "x-pn-realvideo", AVMEDIA_TYPE_VIDEO); | 565 RDT_HANDLER(video, "x-pn-realvideo", AVMEDIA_TYPE_VIDEO); |
| 552 RDT_HANDLER(audio, "x-pn-realaudio", AVMEDIA_TYPE_AUDIO); | 566 RDT_HANDLER(audio, "x-pn-realaudio", AVMEDIA_TYPE_AUDIO); |
| 553 | 567 |
| 554 void av_register_rdt_dynamic_payload_handlers(void) | 568 void av_register_rdt_dynamic_payload_handlers(void) |
| 555 { | 569 { |
| 556 ff_register_dynamic_payload_handler(&ff_rdt_video_handler); | 570 ff_register_dynamic_payload_handler(&ff_rdt_video_handler); |
| 557 ff_register_dynamic_payload_handler(&ff_rdt_audio_handler); | 571 ff_register_dynamic_payload_handler(&ff_rdt_audio_handler); |
| 558 ff_register_dynamic_payload_handler(&ff_rdt_live_video_handler); | 572 ff_register_dynamic_payload_handler(&ff_rdt_live_video_handler); |
| 559 ff_register_dynamic_payload_handler(&ff_rdt_live_audio_handler); | 573 ff_register_dynamic_payload_handler(&ff_rdt_live_audio_handler); |
| 560 } | 574 } |
| OLD | NEW |