Skip to content
Open

pcap #1096

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
LIBS: >
ev asound2 x264 x265 speexdsp png freetype6 zvbi gcrypt tasn1 dvbv5
udev avcodec avformat avfilter swresample swscale gl1-mesa glu1-mesa
srt-gnutls gnutls28 ssl bearssl ebur128 dvbcsa
srt-gnutls gnutls28 ssl bearssl ebur128 dvbcsa pcap
run: |
if [ "${{ matrix.arch }}" != "amd64" ]; then
sudo apt-get install qemu-user-binfmt
Expand All @@ -135,7 +135,7 @@ jobs:
- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew install autoconf automake libtool pkg-config nasm ffmpeg \
brew install autoconf automake libtool pkg-config nasm ffmpeg libpcap \
freetype libebur128 libev libgcrypt libtasn1 speexdsp x264 x265 luajit
BREW_PREFIX="$(brew --prefix)"
set-env HOST_CC "clang"
Expand Down
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
/ts_encrypt
/dvbsrc
/frame
/pcap
4 changes: 4 additions & 0 deletions examples/Build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ multicatudp-src = multicatudp.c
multicatudp-deps = upipe_fsink
multicatudp-libs = libupipe libupipe_modules libupipe_pthread libupump_ev

noinst-targets += pcap
pcap-src = pcap.c
pcap-libs = libupipe libupipe_modules libupipe_pcap libupump_ev bitstream

noinst-targets += rist_rx
rist_rx-src = rist_rx.c
rist_rx-deps = upipe_udpsink upipe_rtpfb
Expand Down
126 changes: 126 additions & 0 deletions examples/pcap.c
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem to do anything useful? Shouln't it use a udpsink to send the packets instead of dropping them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it could do something, don't remember how I tested it exactly.

I can remove this dummy exemple if needed.

Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright (C) 2025 Open Broadcast Systems Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <stdlib.h>
#include <stdio.h>

#include "upipe/uprobe.h"
#include "upipe/uprobe_stdio.h"
#include "upipe/uprobe_prefix.h"
#include "upipe/uprobe_uref_mgr.h"
#include "upipe/uprobe_uclock.h"
#include "upipe/uprobe_upump_mgr.h"
#include "upipe/uprobe_ubuf_mem.h"
#include "upipe/umem.h"
#include "upipe/uclock.h"
#include "upipe/uclock_std.h"
#include "upipe/umem_pool.h"
#include "upipe/udict.h"
#include "upipe/udict_inline.h"
#include "upipe/uref.h"
#include "upipe/uref_std.h"
#include "upipe/upipe.h"
#include "upipe/upump.h"
#include "upump-ev/upump_ev.h"
#include "upipe-pcap/upipe_pcap_src.h"
#include "upipe-modules/upipe_null.h"

#define UPROBE_LOG_LEVEL UPROBE_LOG_INFO
#define UMEM_POOL 512
#define UDICT_POOL_DEPTH 500
#define UREF_POOL_DEPTH 500
#define UBUF_POOL_DEPTH 3000
#define UBUF_SHARED_POOL_DEPTH 50
#define UPUMP_POOL 10
#define UPUMP_BLOCKER_POOL 10

int main(int argc, char **argv)
{
if (argc < 2) {
printf("Usage: %s <input>\n", argv[0]);
exit(-1);
}

const char *input = argv[1];

/* structures managers */
struct upump_mgr *upump_mgr =
upump_ev_mgr_alloc_default(UPUMP_POOL, UPUMP_BLOCKER_POOL);
assert(upump_mgr != NULL);
struct umem_mgr *umem_mgr = umem_pool_mgr_alloc_simple(UMEM_POOL);
struct udict_mgr *udict_mgr =
udict_inline_mgr_alloc(UDICT_POOL_DEPTH, umem_mgr, -1, -1);
struct uref_mgr *uref_mgr =
uref_std_mgr_alloc(UREF_POOL_DEPTH, udict_mgr, 0);
udict_mgr_release(udict_mgr);

struct uclock *uclock = uclock_std_alloc(0);

/* probes */
struct uprobe *uprobe;
uprobe = uprobe_stdio_alloc(NULL, stderr, UPROBE_LOG_DEBUG);
assert(uprobe != NULL);
uprobe = uprobe_uref_mgr_alloc(uprobe, uref_mgr);
assert(uprobe != NULL);
uprobe = uprobe_upump_mgr_alloc(uprobe, upump_mgr);
assert(uprobe != NULL);
uprobe = uprobe_ubuf_mem_alloc(uprobe, umem_mgr, UBUF_POOL_DEPTH,
UBUF_SHARED_POOL_DEPTH);
assert(uprobe != NULL);
uprobe = uprobe_uclock_alloc(uprobe, uclock);
assert(uprobe != NULL);

uref_mgr_release(uref_mgr);
upump_mgr_release(upump_mgr);
umem_mgr_release(umem_mgr);

/* pipes */

struct upipe_mgr *upipe_pcap_src_mgr = upipe_pcap_src_mgr_alloc();
struct upipe *upipe_src = upipe_void_alloc(upipe_pcap_src_mgr,
uprobe_pfx_alloc(uprobe_use(uprobe), UPROBE_LOG_DEBUG, "pcap"));
upipe_mgr_release(upipe_pcap_src_mgr);

upipe_attach_uclock(upipe_src);

struct upipe_mgr *upipe_null_mgr = upipe_null_mgr_alloc();
struct upipe *upipe = upipe_void_alloc_output(upipe_src, upipe_null_mgr,
uprobe_pfx_alloc(uprobe_use(uprobe), UPROBE_LOG_DEBUG, "null"));
upipe_mgr_release(upipe_null_mgr);
upipe_release(upipe);

if (!ubase_check(upipe_set_uri(upipe_src, input))) {
fprintf(stderr, "invalid input\n");
return EXIT_FAILURE;
}

uprobe_release(uprobe);

/* main loop */
upump_mgr_run(upump_mgr, NULL);

uclock_release(uclock);
upipe_release(upipe_src);

return 0;
}
45 changes: 45 additions & 0 deletions include/upipe-pcap/upipe_pcap_src.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2025 Open Broadcast Systems Ltd
*
* Authors: Rafaël Carré
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/** @file
* @short Upipe module to output data from a pcap
*/

#ifndef _UPIPE_PCAP_UPIPE_PCAP_SRC_H_
# define _UPIPE_PCAP_UPIPE_PCAP_SRC_H_

#ifdef __cplusplus
extern "C" {
#endif

#define UPIPE_PCAP_SRC_SIGNATURE UBASE_FOURCC('p','c','a','p')

struct upipe_mgr *upipe_pcap_src_mgr_alloc(void);

#ifdef __cplusplus
}
#endif

#endif
1 change: 1 addition & 0 deletions lib/Build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ subdirs = \
upipe-netmap \
upipe-openssl \
upipe-osx \
upipe-pcap \
upipe-pthread \
upipe-qt \
upipe-speexdsp \
Expand Down
7 changes: 7 additions & 0 deletions lib/upipe-pcap/Build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
lib-targets = libupipe_pcap

libupipe_pcap-desc = pcap file source
libupipe_pcap-so-version = 1.0.0
libupipe_pcap-includes = upipe_pcap_src.h
libupipe_pcap-src = upipe_pcap_src.c
libupipe_pcap-libs = libupipe libpcap bitstream
Loading
Loading