FFmpeg
Loading...
Searching...
No Matches
mpegts_probe.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19/*
20 * Feed hand made packet sequences to the MPEG-TS probe.
21 *
22 * analyze() only counts the sync bytes of null packets (PID 0x1FFF) and of
23 * packets whose adaptation field control (afc) is not 0. Packets are given as
24 * a string with one character each, see put_packet(). The score tells which
25 * packets were counted: 100 if all of them, 0 if (almost) none.
26 */
27
28#include <stdio.h>
29#include <string.h>
30
31#include "libavutil/mem.h"
33#include "libavformat/demux.h"
34
36
37#define NB_PACKETS 12
38#define MAX_PREFIX 8
39#define MAX_STRIDE 204
40
41/*
42 * D: PID 0x100, adaptation field control 1 (payload only)
43 * d: PID 0x100, adaptation field control 0 (reserved)
44 * N: PID 0x1FFF, adaptation field control 1
45 * n: PID 0x1FFF, adaptation field control 0
46 * L: PID 0x1FF, adaptation field control 0 (low byte of the null PID)
47 * H: PID 0x1F00, adaptation field control 0 (high byte of the null PID)
48 */
49static void put_packet(uint8_t *p, char type)
50{
51 int pid = 0x1FFF;
52 int afc = (type == 'D' || type == 'N') ? 1 : 0;
53
54 if (type == 'D' || type == 'd')
55 pid = 0x100;
56 else if (type == 'L')
57 pid = 0x1FF;
58 else if (type == 'H')
59 pid = 0x1F00;
60
61 p[0] = 0x47;
62 p[1] = pid >> 8;
63 p[2] = pid & 0xFF;
64 p[3] = afc << 4;
65}
66
67static void test(const char *name, int prefix_size, int prefix_fill,
68 int stride, const char *packets)
69{
70 uint8_t *buf = av_mallocz(MAX_PREFIX + NB_PACKETS * MAX_STRIDE +
72 AVProbeData pd = { .buf = buf };
73 int i;
74
75 if (!buf)
76 return;
77
78 /* Neither the filler nor the padding contains a sync byte. */
79 memset(buf, prefix_fill, prefix_size);
80 memset(buf + prefix_size, 0xFF, NB_PACKETS * stride);
81 for (i = 0; i < NB_PACKETS; i++)
82 put_packet(buf + prefix_size + i * stride, packets[i]);
83 pd.buf_size = prefix_size + NB_PACKETS * stride;
84
85 printf("%s: %d\n", name, ff_mpegts_demuxer.read_probe(&pd));
86
87 av_free(buf);
88}
89
90int main(void)
91{
92 /* Packets at the start of the buffer, 188, 192 or 204 bytes apart. */
93 test("payload", 0, 0x00, 188, "DDDDDDDDDDDD");
94 test("null, afc 0", 0, 0x00, 188, "nnnnnnnnnnnn");
95 test("payload, then null with afc 0", 0, 0x00, 188, "Dnnnnnnnnnnn");
96 test("payload, then null with afc 0, 192", 0, 0x00, 192, "Dnnnnnnnnnnn");
97 test("payload, then null with afc 0, 204", 0, 0x00, 204, "Dnnnnnnnnnnn");
98 test("null, then payload with afc 0", 0, 0x00, 188, "Nddddddddddd");
99 test("payload and null with afc 0, mixed", 0, 0x00, 188, "DnDnDnDnDnDn");
100 test("payload, a few null with afc 0", 0, 0x00, 188, "DDnDDnDDnDDD");
101 test("null, then PID 0x1FF with afc 0", 0, 0x00, 188, "nLLLLLLLLLLL");
102 test("null, then PID 0x1F00 with afc 0", 0, 0x00, 188, "nHHHHHHHHHHH");
103
104 /* The packets follow 5 bytes which are not part of the stream. */
105 test("null with afc 0, after 0x00", 5, 0x00, 188, "nnnnnnnnnnnn");
106 test("payload with afc 0, after 0xFF", 5, 0xFF, 188, "dddddddddddd");
107 test("payload, after 0xFF", 5, 0xFF, 188, "DDDDDDDDDDDD");
108
109 return 0;
110}
const FFInputFormat ff_mpegts_demuxer
Definition mpegts.c:3876
Main libavformat public API header.
#define AVPROBE_PADDING_SIZE
extra allocated bytes at the end of the probe buffer
Definition avformat.h:487
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
__device__ int printf(const char *,...)
enum MPFType type
Definition jpegmpfenc.c:55
Memory handling functions.
static void test(const char *name, int prefix_size, int prefix_fill, int stride, const char *packets)
static void put_packet(uint8_t *p, char type)
int main(void)
#define NB_PACKETS
#define MAX_STRIDE
#define MAX_PREFIX
const char * name
Definition qsvenc.c:142
This structure contains the data a format has to probe a file.
Definition avformat.h:473
int buf_size
Size of buf except extra allocated bytes.
Definition avformat.h:476
#define stride
#define av_free(p)
#define av_mallocz(s)