Skip to content

Commit ac24d0f

Browse files
committed
upipe_pcap_src: new pipe to read pcap files
1 parent 4798c26 commit ac24d0f

File tree

13 files changed

+903
-5
lines changed

13 files changed

+903
-5
lines changed

.github/workflows/test-suite.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ jobs:
120120
LIBS: >
121121
ev asound2 x264 x265 speexdsp png freetype6 zvbi gcrypt tasn1 dvbv5
122122
udev avcodec avformat avfilter swresample swscale gl1-mesa glu1-mesa
123-
srt-gnutls gnutls28 ssl bearssl ebur128 dvbcsa
123+
srt-gnutls gnutls28 ssl bearssl ebur128 dvbcsa pcap
124124
run: |
125125
if [ "${{ matrix.arch }}" != "amd64" ]; then
126126
sudo apt-get install qemu-user-binfmt
@@ -135,7 +135,7 @@ jobs:
135135
- name: Install dependencies (macOS)
136136
if: runner.os == 'macOS'
137137
run: |
138-
brew install autoconf automake libtool pkg-config nasm ffmpeg \
138+
brew install autoconf automake libtool pkg-config nasm ffmpeg libpcap \
139139
freetype libebur128 libev libgcrypt libtasn1 speexdsp x264 x265 luajit
140140
BREW_PREFIX="$(brew --prefix)"
141141
set-env HOST_CC "clang"
@@ -146,6 +146,7 @@ jobs:
146146
set-env ld_preload_san "$(clang --print-file-name libclang_rt.asan_osx_dynamic.dylib)"
147147
set-env UBSAN_OPTIONS "print_stacktrace=1"
148148
set-env LLVM_DWARFDUMP "dwarfdump"
149+
set-env PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$BREW_PREFIX/opt/libpcap/lib/pkgconfig"
149150
150151
- name: Install bitstream
151152
run: |

examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
/ts_encrypt
2020
/dvbsrc
2121
/frame
22+
/pcap

examples/Build.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ multicatudp-src = multicatudp.c
7070
multicatudp-deps = upipe_fsink
7171
multicatudp-libs = libupipe libupipe_modules libupipe_pthread libupump_ev
7272

73+
noinst-targets += pcap
74+
pcap-src = pcap.c
75+
pcap-libs = libupipe libupipe_modules libupipe_pcap libupump_ev
76+
7377
noinst-targets += rist_rx
7478
rist_rx-src = rist_rx.c
7579
rist_rx-deps = upipe_udpsink upipe_rtpfb

examples/pcap.c

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright (C) 2025 Open Broadcast Systems Ltd
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject
10+
* to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
#include <stdlib.h>
25+
#include <stdio.h>
26+
27+
#include "upipe/uprobe.h"
28+
#include "upipe/uprobe_stdio.h"
29+
#include "upipe/uprobe_prefix.h"
30+
#include "upipe/uprobe_uref_mgr.h"
31+
#include "upipe/uprobe_uclock.h"
32+
#include "upipe/uprobe_upump_mgr.h"
33+
#include "upipe/uprobe_ubuf_mem.h"
34+
#include "upipe/umem.h"
35+
#include "upipe/uclock.h"
36+
#include "upipe/uclock_std.h"
37+
#include "upipe/umem_pool.h"
38+
#include "upipe/udict.h"
39+
#include "upipe/udict_inline.h"
40+
#include "upipe/uref.h"
41+
#include "upipe/uref_std.h"
42+
#include "upipe/upipe.h"
43+
#include "upipe/upump.h"
44+
#include "upump-ev/upump_ev.h"
45+
#include "upipe-pcap/upipe_pcap_src.h"
46+
#include "upipe-modules/upipe_null.h"
47+
48+
#define UPROBE_LOG_LEVEL UPROBE_LOG_INFO
49+
#define UMEM_POOL 512
50+
#define UDICT_POOL_DEPTH 500
51+
#define UREF_POOL_DEPTH 500
52+
#define UBUF_POOL_DEPTH 3000
53+
#define UBUF_SHARED_POOL_DEPTH 50
54+
#define UPUMP_POOL 10
55+
#define UPUMP_BLOCKER_POOL 10
56+
57+
int main(int argc, char **argv)
58+
{
59+
if (argc < 2) {
60+
printf("Usage: %s <input>\n", argv[0]);
61+
exit(-1);
62+
}
63+
64+
const char *input = argv[1];
65+
66+
/* structures managers */
67+
struct upump_mgr *upump_mgr =
68+
upump_ev_mgr_alloc_default(UPUMP_POOL, UPUMP_BLOCKER_POOL);
69+
assert(upump_mgr != NULL);
70+
struct umem_mgr *umem_mgr = umem_pool_mgr_alloc_simple(UMEM_POOL);
71+
struct udict_mgr *udict_mgr =
72+
udict_inline_mgr_alloc(UDICT_POOL_DEPTH, umem_mgr, -1, -1);
73+
struct uref_mgr *uref_mgr =
74+
uref_std_mgr_alloc(UREF_POOL_DEPTH, udict_mgr, 0);
75+
udict_mgr_release(udict_mgr);
76+
77+
struct uclock *uclock = uclock_std_alloc(0);
78+
79+
/* probes */
80+
struct uprobe *uprobe;
81+
uprobe = uprobe_stdio_alloc(NULL, stderr, UPROBE_LOG_DEBUG);
82+
assert(uprobe != NULL);
83+
uprobe = uprobe_uref_mgr_alloc(uprobe, uref_mgr);
84+
assert(uprobe != NULL);
85+
uprobe = uprobe_upump_mgr_alloc(uprobe, upump_mgr);
86+
assert(uprobe != NULL);
87+
uprobe = uprobe_ubuf_mem_alloc(uprobe, umem_mgr, UBUF_POOL_DEPTH,
88+
UBUF_SHARED_POOL_DEPTH);
89+
assert(uprobe != NULL);
90+
uprobe = uprobe_uclock_alloc(uprobe, uclock);
91+
assert(uprobe != NULL);
92+
93+
uref_mgr_release(uref_mgr);
94+
upump_mgr_release(upump_mgr);
95+
umem_mgr_release(umem_mgr);
96+
97+
/* pipes */
98+
99+
struct upipe_mgr *upipe_pcap_src_mgr = upipe_pcap_src_mgr_alloc();
100+
struct upipe *upipe_src = upipe_void_alloc(upipe_pcap_src_mgr,
101+
uprobe_pfx_alloc(uprobe_use(uprobe), UPROBE_LOG_DEBUG, "pcap"));
102+
upipe_mgr_release(upipe_pcap_src_mgr);
103+
104+
upipe_attach_uclock(upipe_src);
105+
106+
struct upipe_mgr *upipe_null_mgr = upipe_null_mgr_alloc();
107+
struct upipe *upipe = upipe_void_alloc_output(upipe_src, upipe_null_mgr,
108+
uprobe_pfx_alloc(uprobe_use(uprobe), UPROBE_LOG_DEBUG, "null"));
109+
upipe_mgr_release(upipe_null_mgr);
110+
upipe_release(upipe);
111+
112+
if (!ubase_check(upipe_set_uri(upipe_src, input))) {
113+
fprintf(stderr, "invalid input\n");
114+
return EXIT_FAILURE;
115+
}
116+
117+
uprobe_release(uprobe);
118+
119+
/* main loop */
120+
upump_mgr_run(upump_mgr, NULL);
121+
122+
uclock_release(uclock);
123+
upipe_release(upipe_src);
124+
125+
return 0;
126+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (C) 2025 Open Broadcast Systems Ltd
3+
*
4+
* Authors: Rafaël Carré
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining
7+
* a copy of this software and associated documentation files (the
8+
* "Software"), to deal in the Software without restriction, including
9+
* without limitation the rights to use, copy, modify, merge, publish,
10+
* distribute, sublicense, and/or sell copies of the Software, and to
11+
* permit persons to whom the Software is furnished to do so, subject
12+
* to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be
15+
* included in all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
/** @file
27+
* @short Upipe module to output data from a pcap
28+
*/
29+
30+
#ifndef _UPIPE_PCAP_UPIPE_PCAP_SRC_H_
31+
# define _UPIPE_PCAP_UPIPE_PCAP_SRC_H_
32+
33+
#ifdef __cplusplus
34+
extern "C" {
35+
#endif
36+
37+
#define UPIPE_PCAP_SRC_SIGNATURE UBASE_FOURCC('p','c','a','p')
38+
39+
struct upipe_mgr *upipe_pcap_src_mgr_alloc(void);
40+
41+
#ifdef __cplusplus
42+
}
43+
#endif
44+
45+
#endif

lib/Build.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ subdirs = \
1919
upipe-netmap \
2020
upipe-openssl \
2121
upipe-osx \
22+
upipe-pcap \
2223
upipe-pthread \
2324
upipe-speexdsp \
2425
upipe-swresample \

lib/upipe-pcap/Build.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
lib-targets = libupipe_pcap
2+
3+
libupipe_pcap-desc = pcap file source
4+
libupipe_pcap-so-version = 1.0.0
5+
libupipe_pcap-includes = upipe_pcap_src.h
6+
libupipe_pcap-src = upipe_pcap_src.c
7+
libupipe_pcap-libs = libupipe libpcap bitstream

0 commit comments

Comments
 (0)