void Decoder::ReadPackets()
{
AVPacket pkt;
int ret;
av_init_packet(&pkt);
ret = av_read_frame(_format_ctx, &pkt);
if (ret < 0)
{
LOG "RET is less than zero. Unpredictable behaviour. Need fix it"<< std::endl;
return;
}
if (pkt.stream_index == _audio_index || pkt.stream_index == _video_index)
{
if(av_dup_packet(&pkt) < 0)
{
LOG "Dup packet is < 0"EL;
return;
}
if (pkt.stream_index == _audio_index)
{
if(!_audio_decoder->Push(pkt))
{
av_free_packet(&pkt);
return;
}
}
else
{
if(!_video_decoder->Push(pkt))
{
av_free_packet(&pkt);
return;
}
}
}
else
av_free_packet(&pkt);
}
dm9pZCBEZWNvZGVyOjpSZWFkUGFja2V0cygpCnsKICAgIEFWUGFja2V0IHBrdDsKCWludCByZXQ7CgoJYXZfaW5pdF9wYWNrZXQoJnBrdCk7CgoJcmV0ID0gYXZfcmVhZF9mcmFtZShfZm9ybWF0X2N0eCwgJnBrdCk7CglpZiAocmV0IDwgMCkKCXsKCSAgICAgTE9HICAiUkVUIGlzIGxlc3MgdGhhbiB6ZXJvLiBVbnByZWRpY3RhYmxlIGJlaGF2aW91ci4gTmVlZCBmaXggaXQiPDwgc3RkOjplbmRsOwoJCSByZXR1cm47Cgl9CglpZiAocGt0LnN0cmVhbV9pbmRleCA9PSBfYXVkaW9faW5kZXggfHwgcGt0LnN0cmVhbV9pbmRleCA9PSBfdmlkZW9faW5kZXgpCgl7CgkJaWYoYXZfZHVwX3BhY2tldCgmcGt0KSA8IDApCgkJewoJCQlMT0cgICJEdXAgcGFja2V0IGlzIDwgMCJFTDsKCQkJcmV0dXJuOwoJCX0KCQlpZiAocGt0LnN0cmVhbV9pbmRleCA9PSBfYXVkaW9faW5kZXgpCgkJewoJCQlpZighX2F1ZGlvX2RlY29kZXItPlB1c2gocGt0KSkKCQkJewoJCQkJYXZfZnJlZV9wYWNrZXQoJnBrdCk7CgkJCQlyZXR1cm47CgkJCX0KCQl9CgkJZWxzZQoJCXsKCQkJaWYoIV92aWRlb19kZWNvZGVyLT5QdXNoKHBrdCkpCgkJCXsKCQkJCWF2X2ZyZWVfcGFja2V0KCZwa3QpOwoJCQkJcmV0dXJuOwoJCQl9CgkJfQoJIH0KCSBlbHNlCgkJYXZfZnJlZV9wYWNrZXQoJnBrdCk7Cn0=