mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-23 16:46:48 +00:00
Use newer FFmpeg api
This commit is contained in:
@@ -157,42 +157,38 @@ void ffmpeg_destroy(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AVFrame* ffmpeg_get_frame() {
|
AVFrame* ffmpeg_get_frame() {
|
||||||
if (decoder_system == SOFTWARE)
|
int err = avcodec_receive_frame(decoder_ctx, dec_frames[next_frame]);
|
||||||
return dec_frames[current_frame];
|
if (err == 0) {
|
||||||
#ifdef HAVE_VDPAU
|
current_frame = next_frame;
|
||||||
else if (decoder_system == VDPAU)
|
next_frame = (current_frame+1) % dec_frames_cnt;
|
||||||
return vdpau_get_frame(dec_frames[current_frame]);
|
|
||||||
#endif
|
if (decoder_system == SOFTWARE)
|
||||||
|
return dec_frames[current_frame];
|
||||||
|
#ifdef HAVE_VDPAU
|
||||||
|
else if (decoder_system == VDPAU)
|
||||||
|
return vdpau_get_frame(dec_frames[current_frame]);
|
||||||
|
#endif
|
||||||
|
} else if (err != AVERROR(EAGAIN)) {
|
||||||
|
char errorstring[512];
|
||||||
|
av_strerror(err, errorstring, sizeof(errorstring));
|
||||||
|
fprintf(stderr, "Receive failed - %d/%s\n", err, errorstring);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// packets must be decoded in order
|
// packets must be decoded in order
|
||||||
// indata must be inlen + FF_INPUT_BUFFER_PADDING_SIZE in length
|
// indata must be inlen + FF_INPUT_BUFFER_PADDING_SIZE in length
|
||||||
int ffmpeg_decode(unsigned char* indata, int inlen) {
|
int ffmpeg_decode(unsigned char* indata, int inlen) {
|
||||||
int err;
|
int err;
|
||||||
int got_pic = 0;
|
|
||||||
|
|
||||||
pkt.data = indata;
|
pkt.data = indata;
|
||||||
pkt.size = inlen;
|
pkt.size = inlen;
|
||||||
|
|
||||||
while (pkt.size > 0) {
|
err = avcodec_send_packet(decoder_ctx, &pkt);
|
||||||
got_pic = 0;
|
if (err < 0) {
|
||||||
err = avcodec_decode_video2(decoder_ctx, dec_frames[next_frame], &got_pic, &pkt);
|
char errorstring[512];
|
||||||
if (err < 0) {
|
av_strerror(err, errorstring, sizeof(errorstring));
|
||||||
char errorstring[512];
|
fprintf(stderr, "Decode failed - %s\n", errorstring);
|
||||||
av_strerror(err, errorstring, sizeof(errorstring));
|
|
||||||
fprintf(stderr, "Decode failed - %s\n", errorstring);
|
|
||||||
got_pic = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
pkt.size -= err;
|
|
||||||
pkt.data += err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (got_pic) {
|
|
||||||
current_frame = next_frame;
|
|
||||||
next_frame = (current_frame+1) % dec_frames_cnt;
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err < 0 ? err : 0;
|
return err < 0 ? err : 0;
|
||||||
|
|||||||
@@ -62,12 +62,12 @@ static int sdl_submit_decode_unit(PDECODE_UNIT decodeUnit) {
|
|||||||
length += entry->length;
|
length += entry->length;
|
||||||
entry = entry->next;
|
entry = entry->next;
|
||||||
}
|
}
|
||||||
|
ffmpeg_decode(ffmpeg_buffer, length);
|
||||||
|
|
||||||
if (SDL_LockMutex(mutex) == 0) {
|
if (SDL_LockMutex(mutex) == 0) {
|
||||||
int ret = ffmpeg_decode(ffmpeg_buffer, length);
|
AVFrame* frame = ffmpeg_get_frame();
|
||||||
if (ret == 1) {
|
if (frame != NULL) {
|
||||||
sdlNextFrame++;
|
sdlNextFrame++;
|
||||||
AVFrame* frame = ffmpeg_get_frame();
|
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
event.type = SDL_USEREVENT;
|
event.type = SDL_USEREVENT;
|
||||||
|
|||||||
Reference in New Issue
Block a user