rtpenc_chain.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * RTP muxer chaining code
  3. * Copyright (c) 2010 Martin Storsjo
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "avformat.h"
  22. #include "rtpenc_chain.h"
  23. AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st,
  24. URLContext *handle, int packet_size)
  25. {
  26. AVFormatContext *rtpctx;
  27. int ret;
  28. AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);
  29. if (!rtp_format)
  30. return NULL;
  31. /* Allocate an AVFormatContext for each output stream */
  32. rtpctx = avformat_alloc_context();
  33. if (!rtpctx)
  34. return NULL;
  35. rtpctx->oformat = rtp_format;
  36. if (!av_new_stream(rtpctx, 0)) {
  37. av_free(rtpctx);
  38. return NULL;
  39. }
  40. /* Copy the max delay setting; the rtp muxer reads this. */
  41. rtpctx->max_delay = s->max_delay;
  42. /* Copy other stream parameters. */
  43. rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio;
  44. /* Set the synchronized start time. */
  45. rtpctx->start_time_realtime = s->start_time_realtime;
  46. avcodec_copy_context(rtpctx->streams[0]->codec, st->codec);
  47. if (handle) {
  48. url_fdopen(&rtpctx->pb, handle);
  49. } else
  50. url_open_dyn_packet_buf(&rtpctx->pb, packet_size);
  51. ret = av_write_header(rtpctx);
  52. if (ret) {
  53. if (handle) {
  54. avio_close(rtpctx->pb);
  55. } else {
  56. uint8_t *ptr;
  57. url_close_dyn_buf(rtpctx->pb, &ptr);
  58. av_free(ptr);
  59. }
  60. avformat_free_context(rtpctx);
  61. return NULL;
  62. }
  63. return rtpctx;
  64. }