rtp_asf.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Microsoft RTP/ASF support.
  3. * Copyright (c) 2008 Ronald S. Bultje
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file libavformat/rtp_asf.c
  23. * @brief Microsoft RTP/ASF support
  24. * @author Ronald S. Bultje <rbultje@ronald.bitfreak.net>
  25. */
  26. #include <libavutil/base64.h>
  27. #include <libavutil/avstring.h>
  28. #include "rtp.h"
  29. #include "rtp_asf.h"
  30. #include "rtsp.h"
  31. #include "asf.h"
  32. void ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p)
  33. {
  34. if (av_strstart(p, "pgmpu:data:application/vnd.ms.wms-hdr.asfv1;base64,", &p)) {
  35. ByteIOContext pb;
  36. RTSPState *rt = s->priv_data;
  37. int len = strlen(p) * 6 / 8;
  38. char *buf = av_mallocz(len);
  39. av_base64_decode(buf, p, len);
  40. init_put_byte(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
  41. if (rt->asf_ctx) {
  42. av_close_input_stream(rt->asf_ctx);
  43. rt->asf_ctx = NULL;
  44. }
  45. av_open_input_stream(&rt->asf_ctx, &pb, "", &asf_demuxer, NULL);
  46. av_free(buf);
  47. rt->asf_ctx->pb = NULL;
  48. }
  49. }
  50. static int
  51. asfrtp_parse_sdp_line (AVFormatContext *s, int stream_index,
  52. PayloadContext *asf, const char *line)
  53. {
  54. if (av_strstart(line, "stream:", &line)) {
  55. RTSPState *rt = s->priv_data;
  56. s->streams[stream_index]->id = strtol(line, NULL, 10);
  57. if (rt->asf_ctx) {
  58. int i;
  59. for (i = 0; i < rt->asf_ctx->nb_streams; i++) {
  60. if (s->streams[stream_index]->id == rt->asf_ctx->streams[i]->id) {
  61. *s->streams[stream_index]->codec =
  62. *rt->asf_ctx->streams[i]->codec;
  63. rt->asf_ctx->streams[i]->codec->extradata_size = 0;
  64. rt->asf_ctx->streams[i]->codec->extradata = NULL;
  65. av_set_pts_info(s->streams[stream_index], 32, 1, 1000);
  66. }
  67. }
  68. }
  69. }
  70. return 0;
  71. }
  72. #define RTP_ASF_HANDLER(n, s, t) \
  73. RTPDynamicProtocolHandler ff_ms_rtp_ ## n ## _handler = { \
  74. s, \
  75. t, \
  76. CODEC_ID_NONE, \
  77. asfrtp_parse_sdp_line, \
  78. };
  79. RTP_ASF_HANDLER(asf_pfv, "x-asf-pf", CODEC_TYPE_VIDEO);
  80. RTP_ASF_HANDLER(asf_pfa, "x-asf-pf", CODEC_TYPE_AUDIO);