Skip to content

Commit

Permalink
MT#60325 allow for kernels without CONFIG_BTREE
Browse files Browse the repository at this point in the history
Possibly relevant to #1834

Change-Id: Iecb9161a44662f9d309a76896cc933dcb5b6c200
  • Loading branch information
rfuchs committed Jun 17, 2024
1 parent a058840 commit 7ce9933
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions kernel-module/xt_RTPENGINE.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@
#include <linux/math64.h>
#include <linux/kthread.h>
#include <linux/wait.h>
#if CONFIG_BTREE
#include <linux/btree.h>
#define KERNEL_PLAYER
#else
#warning "Kernel without CONFIG_BTREE - kernel media player unavailable"
#endif

#include "xt_RTPENGINE.h"

Expand Down Expand Up @@ -589,6 +594,8 @@ struct rtp_parsed {
int rtcp;
};

#ifdef KERNEL_PLAYER

struct play_stream_packet {
struct list_head list;
ktime_t delay;
Expand Down Expand Up @@ -646,6 +653,7 @@ static void free_play_stream_packet(struct play_stream_packet *p);
static void free_play_stream(struct play_stream *s);
static void do_stop_stream(struct play_stream *stream);

#endif


static struct proc_dir_entry *my_proc_root;
Expand All @@ -658,6 +666,7 @@ static rwlock_t table_lock;
static struct re_auto_array calls;
static struct re_auto_array streams;

#ifdef KERNEL_PLAYER
static _rwlock_t media_player_lock;
static struct play_stream_packets **stream_packets;
static unsigned int num_stream_packets;
Expand All @@ -670,6 +679,7 @@ static atomic_t last_play_stream_idx;
static struct timer_thread **timer_threads;
static unsigned int num_timer_threads;
static atomic_t last_timer_thread_idx;
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(5,6,0)
# define PROC_OP_STRUCT file_operations
Expand Down Expand Up @@ -1104,6 +1114,8 @@ static void clear_proc(struct proc_dir_entry **e) {



#ifdef KERNEL_PLAYER

static void __unref_play_stream(struct play_stream *s);
static void __unref_packet_stream(struct play_stream_packets *stream);
static void end_of_stream(struct play_stream *stream);
Expand All @@ -1128,6 +1140,8 @@ static void end_of_stream(struct play_stream *stream);
__unref_packet_stream(s); \
} while (0)

#endif

static void clear_table_proc_files(struct rtpengine_table *t) {
clear_proc(&t->proc_status);
clear_proc(&t->proc_control);
Expand All @@ -1136,6 +1150,8 @@ static void clear_table_proc_files(struct rtpengine_table *t) {
clear_proc(&t->proc_root);
}

#ifdef KERNEL_PLAYER

static void clear_table_player(struct rtpengine_table *t) {
struct play_stream *stream, *ts;
struct play_stream_packets *packets, *tp;
Expand Down Expand Up @@ -1171,6 +1187,8 @@ static void clear_table_player(struct rtpengine_table *t) {
}
}

#endif

static void table_put(struct rtpengine_table *t) {
int i, j, k;
struct re_dest_addr *rda;
Expand Down Expand Up @@ -1219,7 +1237,9 @@ static void table_put(struct rtpengine_table *t) {
}

clear_table_proc_files(t);
#ifdef KERNEL_PLAYER
clear_table_player(t);
#endif
kfree(t);

module_put(THIS_MODULE);
Expand Down Expand Up @@ -3807,6 +3827,8 @@ static void parse_rtcp(struct rtp_parsed *rtp, struct sk_buff *skb) {
rtp->rtcp = 1;
}

#ifdef KERNEL_PLAYER

static void shut_threads(struct timer_thread **thr, unsigned int nt) {
unsigned int i;

Expand Down Expand Up @@ -4672,6 +4694,8 @@ static int cmd_free_packet_stream(struct rtpengine_table *t, unsigned int idx) {
return 0;
}

#endif


static const size_t min_req_sizes[__REMG_LAST] = {
[REMG_INIT] = sizeof(struct rtpengine_command_init),
Expand Down Expand Up @@ -4745,12 +4769,14 @@ static inline ssize_t proc_control_read_write(struct file *file, char __user *ub
struct rtpengine_command_add_stream *add_stream;
struct rtpengine_command_del_stream *del_stream;
struct rtpengine_command_packet *packet;
#ifdef KERNEL_PLAYER
struct rtpengine_command_init_play_streams *init_play_streams;
struct rtpengine_command_get_packet_stream *get_packet_stream;
struct rtpengine_command_play_stream_packet *play_stream_packet;
struct rtpengine_command_play_stream *play_stream;
struct rtpengine_command_stop_stream *stop_stream;
struct rtpengine_command_free_packet_stream *free_packet_stream;
#endif

char *storage;
} msg;
Expand Down Expand Up @@ -4841,6 +4867,8 @@ static inline ssize_t proc_control_read_write(struct file *file, char __user *ub
err = stream_packet(t, &msg.packet->packet, buflen - sizeof(*msg.packet));
break;

#ifdef KERNEL_PLAYER

case REMG_INIT_PLAY_STREAMS:
err = init_play_streams(msg.init_play_streams->num_play_streams,
msg.init_play_streams->num_packet_streams);
Expand Down Expand Up @@ -4871,6 +4899,8 @@ static inline ssize_t proc_control_read_write(struct file *file, char __user *ub
err = cmd_free_packet_stream(t, msg.free_packet_stream->packet_stream_idx);
break;

#endif

default:
printk(KERN_WARNING "xt_RTPENGINE unimplemented op %u\n", cmd);
err = -EINVAL;
Expand Down Expand Up @@ -6668,12 +6698,16 @@ static int __init init(void) {
if (ret)
goto fail;

#ifdef KERNEL_PLAYER
_rwlock_init(&media_player_lock);
#endif

return 0;

fail:
#ifdef KERNEL_PLAYER
shut_all_threads();
#endif
clear_proc(&proc_control);
clear_proc(&proc_list);
clear_proc(&my_proc_root);
Expand All @@ -6687,17 +6721,21 @@ static void __exit fini(void) {
printk(KERN_NOTICE "Unregistering xt_RTPENGINE module\n");
xt_unregister_targets(xt_rtpengine_regs, ARRAY_SIZE(xt_rtpengine_regs));

#ifdef KERNEL_PLAYER
shut_all_threads();
#endif
clear_proc(&proc_control);
clear_proc(&proc_list);
clear_proc(&my_proc_root);

auto_array_free(&streams);
auto_array_free(&calls);

#ifdef KERNEL_PLAYER
// these should be empty
kfree(play_streams);
kfree(stream_packets);
#endif
}

module_init(init);
Expand Down

0 comments on commit 7ce9933

Please sign in to comment.