@@ -44,9 +44,8 @@ bool quicsy_decoder_open(decoder_t* dec, const char* filename) {
4444 log (" finding the proper decoder (CODEC)" );
4545
4646 av_codec = avcodec_find_decoder (av_codec_params->codec_id );
47- if (av_codec == NULL ) {
48- err_log (" CODEC: couldn't find proper decoder" );
49- break ;
47+ if (!av_codec) {
48+ continue ;
5049 }
5150 if (av_codec_params->codec_type == AVMEDIA_TYPE_VIDEO) {
5251 video_stream_index = i;
@@ -108,24 +107,9 @@ bool quicsy_decoder_read_frame(decoder_t* dec, uint8_t* frame_buffer, int64_t* p
108107 auto & sws_scaler_ctx = dec->sws_scaler_ctx ;
109108
110109 // Decode one frame
111- int response;
112- bool finished = false ;
113-
114- while (!finished)
115- {
116- if (response = (av_read_frame (av_format_ctx, av_packet)) < 0 )
117- {
118- if (response == AVERROR_EOF)
119- {
120- finished = true ;
121- }
122- else
123- {
124- exit (0 );
125- }
126- }
127-
128- if (av_packet->stream_index != video_stream_index) {
110+ int response;
111+ while (av_read_frame (av_format_ctx, av_packet) >= 0 ) {
112+ if (av_packet->stream_index != video_stream_index) {
129113 log (" AVPacket->pts %" PRId64, av_packet->pts );
130114 av_packet_unref (av_packet);
131115 continue ;
@@ -142,27 +126,24 @@ bool quicsy_decoder_read_frame(decoder_t* dec, uint8_t* frame_buffer, int64_t* p
142126 if (response == AVERROR (EAGAIN) || response == AVERROR_EOF) {
143127 av_packet_unref (av_packet);
144128 continue ;
145- } else if (response < 0 ) {
129+ } else if (response < 0 ) {
146130 log (" Error while receiving a frame from the decoder" );
147131 // FIXME: err_log("Error while receiving a frame from the decoder: %s", av_err2str(response));
148132 return false ;
149133 }
150134
151135 av_packet_unref (av_packet);
152136 break ;
153- }
154-
155- *pts = av_frame->pts ;
137+ }
156138
157- // Set up sws scaler
158- if (!sws_scaler_ctx)
159- {
160- sws_scaler_ctx = sws_getContext (width, height, av_codec_ctx->pix_fmt ,
161- width, height, AV_PIX_FMT_RGB0,
162- SWS_BILINEAR, NULL , NULL , NULL );
163- }
139+ *pts = av_frame->pts ;
140+
141+ // Set up sws scaler
142+ sws_scaler_ctx = sws_getContext (width, height, av_codec_ctx->pix_fmt ,
143+ width, height, AV_PIX_FMT_RGB0,
144+ SWS_BILINEAR, NULL , NULL , NULL );
164145
165- if (!sws_scaler_ctx) {
146+ if (!sws_scaler_ctx) {
166147 printf (" Couldn't initialize sw scaler\n " );
167148 return false ;
168149 }
0 commit comments