|
| 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 | +} |
0 commit comments