高清节目高比特率的情况下,外接usb硬盘进行timeshift,发现performance不足,流数据丢失现象。
研究发现,对流中的图像组和图像头定位算法耗时过多,经过研究找到改善方法。下面是解决方法描述:
function dvb_index() in RecordingThread.cpp, is used to locate sequence header and picture header in ts stream, I frame(slice) size and number of pictures for trick play.
however, old algorithm scan each byte one by one, and has bad efficiency, 90Mbps from test.
If skip by size of one ts packet during the parsing, it increase a lot the efficiency, about 1500Mbps from test.
A fact, that most streams sequence header and picture header are located in the first two ts packets when playload_start_indicator is set in ts header.
I had programmed a tool and scan many streams, and got such result at last.
Then this PR will adopt this fact, also find the way to cover those streams beyond the assumpation.
If a picture header or sequence header is located in the first two ts packets when playload_start_indicator is set, we say it satify the assumption.
The new algorithm, first skip bytes one by one as old algorithm, we have a counter(matchcount), when we located a header and satify the assumption, increase matchcount by one, else clear it to zero.
if matchcount reach a value, such as 10, enable skip by ts packet size each step, during this, we compare frame count between two sequence header, if the increase number less then a value, such as 2, it means, the new algothrim miss some frames during parsing, then switch back to old mechanism.
为了检验该改善假定的通用性,有写测试软件:
. Scan 某个硬盘中的码流
. 找到码流中的视频pid
. Scan视频,查找Sequence header和picture header,判断是否处于playload_start_indicator设置后的前两个packets中。