You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.2KB

  1. /*
  2. * Common code for the RTP depacketization of MPEG-1/2 formats.
  3. * Copyright (c) 2002 Fabrice Bellard
  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 "libavutil/attributes.h"
  22. #include "libavutil/intreadwrite.h"
  23. #include "rtpdec_formats.h"
  24. static int mpeg_parse_packet(AVFormatContext *ctx, PayloadContext *data,
  25. AVStream *st, AVPacket *pkt, uint32_t *timestamp,
  26. const uint8_t *buf, int len, uint16_t seq,
  27. int flags)
  28. {
  29. unsigned int h;
  30. if (len <= 4)
  31. return AVERROR_INVALIDDATA;
  32. h = AV_RB32(buf);
  33. buf += 4;
  34. len -= 4;
  35. if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && h & (1 << 26)) {
  36. /* MPEG-2 */
  37. if (len <= 4)
  38. return AVERROR_INVALIDDATA;
  39. buf += 4;
  40. len -= 4;
  41. }
  42. if (av_new_packet(pkt, len) < 0)
  43. return AVERROR(ENOMEM);
  44. memcpy(pkt->data, buf, len);
  45. pkt->stream_index = st->index;
  46. return 0;
  47. }
  48. RTPDynamicProtocolHandler ff_mpeg_audio_dynamic_handler = {
  49. .codec_type = AVMEDIA_TYPE_AUDIO,
  50. .codec_id = AV_CODEC_ID_MP3,
  51. .need_parsing = AVSTREAM_PARSE_FULL,
  52. .parse_packet = mpeg_parse_packet,
  53. .static_payload_id = 14,
  54. };
  55. RTPDynamicProtocolHandler ff_mpeg_video_dynamic_handler = {
  56. .codec_type = AVMEDIA_TYPE_VIDEO,
  57. .codec_id = AV_CODEC_ID_MPEG2VIDEO,
  58. .need_parsing = AVSTREAM_PARSE_FULL,
  59. .parse_packet = mpeg_parse_packet,
  60. .static_payload_id = 32,
  61. };