Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vp8: add packetize handler #1868

Merged
merged 1 commit into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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