mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-18 11:54:30 +01:00
sceVideocodec: Picture records, SEI and sequence timing, for UMD Video
The VSH's UMD Video player reads what the ME writes beside each decoded picture, which games' mpeg.prx only passes through (pspautotests video/mpeg/avcdetail, recorded on a PSP): - Given a 0x540-byte buffer at ctx+0x38, as mpeg_vsh.prx provides in the modes the player uses, the ME points each picture descriptor's +0x24 and +0x28 at two 0xA4-byte records for it. The first is the picture's SEI record: cpb_removal_delay at +0x18, dpb_output_delay at +0x1C, the pic_struct at +0x20 (which the player picks a duration with), and flags of 7 for a keyframe and 2 otherwise. sceVideocodecGetSEI writes the record of the last access unit decoded to the buffer at ctx+0x50. - A descriptor's +0x20 is 1 for a keyframe. The player drops every picture after starting or seeking until it sees one. - The 0x64 bytes at ctx+0x30 carry the VUI timing (num_units_in_tick at 240000 ticks a second), which the player checks against 5005 for film. All of it comes from what ffmpeg's H.264 parser reports per access unit, which AvcDecoder now hands back with each picture. Each picture also goes into the next of the four frame stores, as the ME rotates through its own: the player converts a picture in strips spread over its next few frames, while decoding goes on. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
7d2663bf73
commit
9f5d074a0e
4 files changed
+156
-3
No files matched your search
@@ -166,6 +166,8 @@ void AvcDecoder::Flush() {
|
||||
#endif
|
||||
decoded_.clear();
|
||||
outputTicks_.clear();
|
||||
timings_.clear();
|
||||
lastTiming_ = AvcTiming();
|
||||
bufferingTick_ = 0;
|
||||
firstTiming_ = true;
|
||||
nextIndex_ = 0;
|
||||
@@ -360,6 +362,7 @@ void AvcDecoder::Release() {
|
||||
decoded_.pop_front();
|
||||
outputTicks_.erase(d.index);
|
||||
released_++;
|
||||
auto timing = timings_.find(d.index);
|
||||
outFrames_.push_back(d.frame);
|
||||
AvcPicture pic;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@@ -368,10 +371,44 @@ void AvcDecoder::Release() {
|
||||
}
|
||||
pic.width = d.frame->width;
|
||||
pic.height = d.frame->height;
|
||||
if (timing != timings_.end()) {
|
||||
pic.timing = timing->second;
|
||||
timings_.erase(timing);
|
||||
}
|
||||
pictures_.push_back(pic);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_FFMPEG
|
||||
// The parser doesn't report pic_struct itself, only what it decides from it (h264_parser.c).
|
||||
static int PicStructFromParser(const AVCodecParserContext *parser) {
|
||||
if (parser->picture_structure == AV_PICTURE_STRUCTURE_TOP_FIELD) {
|
||||
return 1;
|
||||
}
|
||||
if (parser->picture_structure == AV_PICTURE_STRUCTURE_BOTTOM_FIELD) {
|
||||
return 2;
|
||||
}
|
||||
switch (parser->repeat_pict) {
|
||||
case 1: return parser->field_order == AV_FIELD_TT ? 3 : (parser->field_order == AV_FIELD_BB ? 4 : 0);
|
||||
case 2: return parser->field_order == AV_FIELD_BB ? 6 : 5;
|
||||
case 3: return 7;
|
||||
case 5: return 8;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool AvcDecoder::FrameRate(int *num, int *den) const {
|
||||
#ifdef USE_FFMPEG
|
||||
if (codecCtx_ && codecCtx_->framerate.num > 0 && codecCtx_->framerate.den > 0) {
|
||||
*num = codecCtx_->framerate.num;
|
||||
*den = codecCtx_->framerate.den;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
int AvcDecoder::DecodePictures(const u8 *data, int size) {
|
||||
ClearPictures();
|
||||
#ifdef USE_FFMPEG
|
||||
@@ -384,6 +421,7 @@ int AvcDecoder::DecodePictures(const u8 *data, int size) {
|
||||
// cpb_removal_delay and dpb_output_delay here, and whether this unit starts a buffering period.
|
||||
bool timed = false;
|
||||
s64 removalTick = 0;
|
||||
lastTiming_ = AvcTiming();
|
||||
if (parser_) {
|
||||
u8 *out = nullptr;
|
||||
int outSize = 0;
|
||||
@@ -398,7 +436,14 @@ int AvcDecoder::DecodePictures(const u8 *data, int size) {
|
||||
}
|
||||
firstTiming_ = false;
|
||||
outputTicks_[index] = removalTick + parser_->pts_dts_delta;
|
||||
lastTiming_.picTiming = true;
|
||||
lastTiming_.bufferingPeriod = parser_->dts_sync_point > 0;
|
||||
lastTiming_.cpbRemovalDelay = parser_->dts_ref_dts_delta;
|
||||
lastTiming_.dpbOutputDelay = parser_->pts_dts_delta;
|
||||
}
|
||||
lastTiming_.picStruct = PicStructFromParser(parser_);
|
||||
lastTiming_.keyFrame = parser_->key_frame == 1;
|
||||
timings_[index] = lastTiming_;
|
||||
}
|
||||
|
||||
FeedFfmpeg(data, size, index);
|
||||
|
||||
Reference in new issue
Block a user