Split codec_id reading
Receive codec id and convert it to AVCodecID separately. This will allow the caller to distinguish between EOS and unknown codec id.
This commit is contained in:
parent
230b8274b9
commit
953edfd1df
1 changed files with 20 additions and 9 deletions
|
@ -18,17 +18,10 @@
|
||||||
#define SC_PACKET_PTS_MASK (SC_PACKET_FLAG_KEY_FRAME - 1)
|
#define SC_PACKET_PTS_MASK (SC_PACKET_FLAG_KEY_FRAME - 1)
|
||||||
|
|
||||||
static enum AVCodecID
|
static enum AVCodecID
|
||||||
sc_demuxer_recv_codec_id(struct sc_demuxer *demuxer) {
|
sc_demuxer_to_avcodec_id(uint32_t codec_id) {
|
||||||
uint8_t data[4];
|
|
||||||
ssize_t r = net_recv_all(demuxer->socket, data, 4);
|
|
||||||
if (r < 4) {
|
|
||||||
return AV_CODEC_ID_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SC_CODEC_ID_H264 UINT32_C(0x68323634) // "h264" in ASCII
|
#define SC_CODEC_ID_H264 UINT32_C(0x68323634) // "h264" in ASCII
|
||||||
#define SC_CODEC_ID_H265 UINT32_C(0x68323635) // "h265" in ASCII
|
#define SC_CODEC_ID_H265 UINT32_C(0x68323635) // "h265" in ASCII
|
||||||
#define SC_CODEC_ID_AV1 UINT32_C(0x00617631) // "av1" in ASCII
|
#define SC_CODEC_ID_AV1 UINT32_C(0x00617631) // "av1" in ASCII
|
||||||
uint32_t codec_id = sc_read32be(data);
|
|
||||||
switch (codec_id) {
|
switch (codec_id) {
|
||||||
case SC_CODEC_ID_H264:
|
case SC_CODEC_ID_H264:
|
||||||
return AV_CODEC_ID_H264;
|
return AV_CODEC_ID_H264;
|
||||||
|
@ -42,6 +35,18 @@ sc_demuxer_recv_codec_id(struct sc_demuxer *demuxer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
sc_demuxer_recv_codec_id(struct sc_demuxer *demuxer, uint32_t *codec_id) {
|
||||||
|
uint8_t data[4];
|
||||||
|
ssize_t r = net_recv_all(demuxer->socket, data, 4);
|
||||||
|
if (r < 4) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*codec_id = sc_read32be(data);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
sc_demuxer_recv_packet(struct sc_demuxer *demuxer, AVPacket *packet) {
|
sc_demuxer_recv_packet(struct sc_demuxer *demuxer, AVPacket *packet) {
|
||||||
// The video stream contains raw packets, without time information. When we
|
// The video stream contains raw packets, without time information. When we
|
||||||
|
@ -196,7 +201,13 @@ static int
|
||||||
run_demuxer(void *data) {
|
run_demuxer(void *data) {
|
||||||
struct sc_demuxer *demuxer = data;
|
struct sc_demuxer *demuxer = data;
|
||||||
|
|
||||||
enum AVCodecID codec_id = sc_demuxer_recv_codec_id(demuxer);
|
uint32_t raw_codec_id;
|
||||||
|
bool ok = sc_demuxer_recv_codec_id(demuxer, &raw_codec_id);
|
||||||
|
if (!ok) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum AVCodecID codec_id = sc_demuxer_to_avcodec_id(raw_codec_id);
|
||||||
if (codec_id == AV_CODEC_ID_NONE) {
|
if (codec_id == AV_CODEC_ID_NONE) {
|
||||||
// Error already logged
|
// Error already logged
|
||||||
goto end;
|
goto end;
|
||||||
|
|
Loading…
Reference in a new issue