Skip to content

Commit 90ee52d

Browse files
committed
rtpdec_h2645: use common decode_frame function
the handling is mostly the same + change MOD_NAME to rtpdec_h2645 (HEVC inclusive)
1 parent 4ced077 commit 90ee52d

File tree

3 files changed

+9
-50
lines changed

3 files changed

+9
-50
lines changed

src/rtp/rtpdec_h264.c

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
/// type was 1-23 representing H.264 NAL type
6464
#define H264_NAL 32
6565

66-
#define MOD_NAME "[rtpdec_h264] "
66+
#define MOD_NAME "[rtpdec_h2645] "
6767

6868
static const uint8_t start_sequence[] = { 0, 0, 0, 1 };
6969

@@ -415,14 +415,18 @@ get_sps_pps_frame(const struct video_desc *desc,
415415
return frame;
416416
}
417417

418-
int decode_frame_h264(struct coded_data *cdata, void *decode_data) {
418+
int decode_frame_h2645(struct coded_data *cdata, void *decode_data) {
419419
struct coded_data *orig = cdata;
420420

421421
int total_length = 0;
422422

423423
struct decode_data_rtsp *data = decode_data;
424424
struct video_frame *frame = data->frame;
425425
frame->frame_type = BFRAME;
426+
assert(frame->color_spec == H264 || frame->color_spec == H265);
427+
bool (*const decode_nal_unit)(struct video_frame *, int *, int,
428+
unsigned char **, uint8_t *, int) =
429+
frame->color_spec == H264 ? decode_h264_nal_unit : decode_hevc_nal_unit;
426430

427431
for (int pass = 0; pass < 2; pass++) {
428432
unsigned char *dst = NULL;
@@ -442,49 +446,7 @@ int decode_frame_h264(struct coded_data *cdata, void *decode_data) {
442446
while (cdata != NULL) {
443447
rtp_packet *pckt = cdata->data;
444448

445-
if (!decode_h264_nal_unit(frame, &total_length, pass, &dst, (uint8_t *) pckt->data, pckt->data_len)) {
446-
return false;
447-
}
448-
449-
cdata = cdata->nxt;
450-
}
451-
}
452-
453-
if (frame->frame_type == INTRA) {
454-
write_sps_pps(frame, data);
455-
}
456-
457-
return true;
458-
}
459-
460-
int decode_frame_hevc(struct coded_data *cdata, void *decode_data) {
461-
struct coded_data *orig = cdata;
462-
463-
int total_length = 0;
464-
465-
struct decode_data_rtsp *data = decode_data;
466-
struct video_frame *frame = data->frame;
467-
frame->frame_type = BFRAME;
468-
469-
for (int pass = 0; pass < 2; pass++) {
470-
unsigned char *dst = NULL;
471-
472-
if (pass > 0) {
473-
cdata = orig;
474-
if(frame->frame_type == INTRA){
475-
total_length+=data->offset_len;
476-
}
477-
frame->tiles[0].data_len = total_length;
478-
assert(frame->tiles[0].data == NULL);
479-
frame->tiles[0].data = malloc(total_length);
480-
frame->callbacks.data_deleter = vf_data_deleter;
481-
dst = (unsigned char *) frame->tiles[0].data + total_length;
482-
}
483-
484-
while (cdata != NULL) {
485-
rtp_packet *pckt = cdata->data;
486-
487-
if (!decode_hevc_nal_unit(frame, &total_length, pass, &dst, (uint8_t *) pckt->data, pckt->data_len)) {
449+
if (!decode_nal_unit(frame, &total_length, pass, &dst, (uint8_t *) pckt->data, pckt->data_len)) {
488450
return false;
489451
}
490452

src/rtp/rtpdec_h264.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ struct video_desc;
105105
((is_hevc) ? HEVC_NALU_HDR_GET_TYPE((nal)) \
106106
: H264_NALU_HDR_GET_TYPE((nal)))
107107

108-
int decode_frame_h264(struct coded_data *cdata, void *decode_data);
109-
int decode_frame_hevc(struct coded_data *cdata, void *decode_data);
108+
int decode_frame_h2645(struct coded_data *cdata, void *decode_data);
110109
struct video_frame *get_sps_pps_frame(const struct video_desc *desc,
111110
struct decode_data_rtsp *decode_data);
112111
int width_height_from_h264_sps(int *widthOut, int *heightOut,

src/video_capture/rtsp.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,9 +928,7 @@ init_rtsp(struct rtsp_state *s) {
928928
}
929929
if (s->vrtsp_state.desc.color_spec == H264 ||
930930
s->vrtsp_state.desc.color_spec == H265) {
931-
s->vrtsp_state.decode_data.decode =
932-
s->vrtsp_state.desc.color_spec == H264 ? decode_frame_h264
933-
: decode_frame_hevc;
931+
s->vrtsp_state.decode_data.decode = decode_frame_h2645;
934932
/* get start nal size attribute from sdp file */
935933
const int len_nals = get_nals(sdp_file,
936934
s->vrtsp_state.desc.color_spec,

0 commit comments

Comments
 (0)