Skip to content

Commit

Permalink
vp8: add packetize handler (#1868)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredh committed May 29, 2022
1 parent 5b044cc commit cc5ccc2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
62 changes: 62 additions & 0 deletions modules/vp8/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,65 @@ int vp8_encode(struct videnc_state *ves, bool update,

return 0;
}


static int peek_vp8_bitstream(bool *key_frame,
const uint8_t *buf, size_t size)
{
if (size < 3)
return EBADMSG;

uint8_t frame_type = buf[0] & 1;
uint8_t profile = (buf[0] >> 1) & 7;

if (profile > 3) {
warning("vp8: Invalid profile %u.\n", profile);
return EPROTO;
}

if (frame_type == 0) {

if (size < 10)
return EBADMSG;

const uint8_t *c = buf + 3;

if (c[0] != 0x9d || c[1] != 0x01 || c[2] != 0x2a) {

warning("vp8: Invalid sync code %w.\n", c, 3);
return EPROTO;
}
}

*key_frame = frame_type == 0;

return 0;
}


int vp8_encode_packetize(struct videnc_state *ves,
const struct vidpacket *pkt)
{
bool key_frame = false;
uint64_t rtp_ts;
int err;

if (!ves || !pkt)
return EINVAL;

++ves->picid;

err = peek_vp8_bitstream(&key_frame, pkt->buf, pkt->size);
if (err)
return err;

rtp_ts = video_calc_rtp_timestamp_fix(pkt->timestamp);

err = packetize(true, pkt->buf, pkt->size,
ves->pktsize, !key_frame, 0,
ves->picid, rtp_ts, ves->pkth, ves->arg);
if (err)
return err;

return 0;
}
1 change: 1 addition & 0 deletions modules/vp8/vp8.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static struct vp8_vidcodec vp8 = {
.decupdh = vp8_decode_update,
.dech = vp8_decode,
.fmtp_ench = vp8_fmtp_enc,
.packetizeh = vp8_encode_packetize,
},
.max_fs = 3600,
};
Expand Down
2 changes: 2 additions & 0 deletions modules/vp8/vp8.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ int vp8_encode_update(struct videnc_state **vesp, const struct vidcodec *vc,
videnc_packet_h *pkth, void *arg);
int vp8_encode(struct videnc_state *ves, bool update,
const struct vidframe *frame, uint64_t timestamp);
int vp8_encode_packetize(struct videnc_state *ves,
const struct vidpacket *packet);


/* Decode */
Expand Down

0 comments on commit cc5ccc2

Please sign in to comment.