1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * Common code for the RTP depacketization of MPEG-1/2 formats.
3cabdff1aSopenharmony_ci * Copyright (c) 2002 Fabrice Bellard
4cabdff1aSopenharmony_ci *
5cabdff1aSopenharmony_ci * This file is part of FFmpeg.
6cabdff1aSopenharmony_ci *
7cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
8cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
9cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
10cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
11cabdff1aSopenharmony_ci *
12cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
13cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
14cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15cabdff1aSopenharmony_ci * Lesser General Public License for more details.
16cabdff1aSopenharmony_ci *
17cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
18cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
19cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20cabdff1aSopenharmony_ci */
21cabdff1aSopenharmony_ci
22cabdff1aSopenharmony_ci#include "libavutil/attributes.h"
23cabdff1aSopenharmony_ci#include "libavutil/intreadwrite.h"
24cabdff1aSopenharmony_ci#include "rtpdec_formats.h"
25cabdff1aSopenharmony_ci
26cabdff1aSopenharmony_cistatic int mpeg_parse_packet(AVFormatContext *ctx, PayloadContext *data,
27cabdff1aSopenharmony_ci                             AVStream *st, AVPacket *pkt, uint32_t *timestamp,
28cabdff1aSopenharmony_ci                             const uint8_t *buf, int len, uint16_t seq,
29cabdff1aSopenharmony_ci                             int flags)
30cabdff1aSopenharmony_ci{
31cabdff1aSopenharmony_ci    unsigned int h;
32cabdff1aSopenharmony_ci    int ret;
33cabdff1aSopenharmony_ci    if (len <= 4)
34cabdff1aSopenharmony_ci        return AVERROR_INVALIDDATA;
35cabdff1aSopenharmony_ci    h    = AV_RB32(buf);
36cabdff1aSopenharmony_ci    buf += 4;
37cabdff1aSopenharmony_ci    len -= 4;
38cabdff1aSopenharmony_ci    if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && h & (1 << 26)) {
39cabdff1aSopenharmony_ci        /* MPEG-2 */
40cabdff1aSopenharmony_ci        if (len <= 4)
41cabdff1aSopenharmony_ci            return AVERROR_INVALIDDATA;
42cabdff1aSopenharmony_ci        buf += 4;
43cabdff1aSopenharmony_ci        len -= 4;
44cabdff1aSopenharmony_ci    }
45cabdff1aSopenharmony_ci    if ((ret = av_new_packet(pkt, len)) < 0)
46cabdff1aSopenharmony_ci        return ret;
47cabdff1aSopenharmony_ci    memcpy(pkt->data, buf, len);
48cabdff1aSopenharmony_ci    pkt->stream_index = st->index;
49cabdff1aSopenharmony_ci    return 0;
50cabdff1aSopenharmony_ci}
51cabdff1aSopenharmony_ci
52cabdff1aSopenharmony_ciconst RTPDynamicProtocolHandler ff_mpeg_audio_dynamic_handler = {
53cabdff1aSopenharmony_ci    .codec_type        = AVMEDIA_TYPE_AUDIO,
54cabdff1aSopenharmony_ci    .codec_id          = AV_CODEC_ID_MP3,
55cabdff1aSopenharmony_ci    .need_parsing      = AVSTREAM_PARSE_FULL,
56cabdff1aSopenharmony_ci    .parse_packet      = mpeg_parse_packet,
57cabdff1aSopenharmony_ci    .static_payload_id = 14,
58cabdff1aSopenharmony_ci};
59cabdff1aSopenharmony_ci
60cabdff1aSopenharmony_ciconst RTPDynamicProtocolHandler ff_mpeg_video_dynamic_handler = {
61cabdff1aSopenharmony_ci    .codec_type        = AVMEDIA_TYPE_VIDEO,
62cabdff1aSopenharmony_ci    .codec_id          = AV_CODEC_ID_MPEG2VIDEO,
63cabdff1aSopenharmony_ci    .need_parsing      = AVSTREAM_PARSE_FULL,
64cabdff1aSopenharmony_ci    .parse_packet      = mpeg_parse_packet,
65cabdff1aSopenharmony_ci    .static_payload_id = 32,
66cabdff1aSopenharmony_ci};
67