@@ -94,7 +94,9 @@ static int ffmpeg_camera_get_initial_options(
9494
9595 if (result < 0 )
9696 {
97- RARCH_ERR ("[FFMPEG] Failed to set option: %s.\n" , av_err2str (result ));
97+ char msg [AV_ERROR_MAX_STRING_SIZE ];
98+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
99+ RARCH_ERR ("[FFMPEG] Failed to set option: %s.\n" , msg );
98100 goto error ;
99101 }
100102 }
@@ -153,22 +155,28 @@ static int ffmpeg_camera_open_device(ffmpeg_camera_t *ffmpeg)
153155
154156 if (result < 0 )
155157 {
156- RARCH_ERR ("[FFMPEG] Failed to copy options: %s.\n" , av_err2str (result ));
158+ char msg [AV_ERROR_MAX_STRING_SIZE ];
159+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
160+ RARCH_ERR ("[FFMPEG] Failed to copy options: %s.\n" , msg );
157161 goto done ;
158162 }
159163
160164 result = avformat_open_input (& ffmpeg -> format_context , ffmpeg -> url , ffmpeg -> input_format , & options );
161165 if (result < 0 )
162166 {
163- RARCH_WARN ("[FFMPEG] Failed to open video input device \"%s\": %s.\n" , ffmpeg -> url , av_err2str (result ));
167+ char msg [AV_ERROR_MAX_STRING_SIZE ];
168+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
169+ RARCH_WARN ("[FFMPEG] Failed to open video input device \"%s\": %s.\n" , ffmpeg -> url , msg );
164170
165171 if (ffmpeg -> options )
166172 { /* If we're not already requesting the default format... */
167173
168174 result = avformat_open_input (& ffmpeg -> format_context , ffmpeg -> url , ffmpeg -> input_format , NULL );
169175 if (result < 0 )
170176 {
171- RARCH_ERR ("[FFMPEG] Failed to open the same device in its default format: %s.\n" , av_err2str (result ));
177+ char msg [AV_ERROR_MAX_STRING_SIZE ];
178+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
179+ RARCH_ERR ("[FFMPEG] Failed to open the same device in its default format: %s.\n" , msg );
172180 goto done ;
173181 }
174182 }
@@ -177,8 +185,8 @@ static int ffmpeg_camera_open_device(ffmpeg_camera_t *ffmpeg)
177185done :
178186 if (options )
179187 {
180- const AVDictionaryEntry prev ;
181- while ((e = av_dict_get (options , "" , & prev , AV_DICT_IGNORE_SUFFIX )))
188+ const AVDictionaryEntry * prev = NULL ;
189+ while ((e = av_dict_get (options , "" , prev , AV_DICT_IGNORE_SUFFIX )))
182190 {
183191 /* av_dict_iterate isn't always available, so we use av_dict_get's legacy behavior instead */
184192 RARCH_WARN ("[FFMPEG] Unrecognized option on video input device: %s=%s.\n" , e -> key , e -> value );
@@ -232,7 +240,9 @@ static void *ffmpeg_camera_init(const char *device, uint64_t caps, unsigned widt
232240 result = ffmpeg_camera_get_initial_options (ffmpeg -> input_format , & ffmpeg -> options , caps , width , height );
233241 if (result < 0 )
234242 {
235- RARCH_ERR ("[FFMPEG] Failed to get initial options: %s.\n" , av_err2str (result ));
243+ char msg [AV_ERROR_MAX_STRING_SIZE ];
244+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
245+ RARCH_ERR ("[FFMPEG] Failed to get initial options: %s.\n" , msg );
236246 goto error ;
237247 }
238248
@@ -245,7 +255,9 @@ static void *ffmpeg_camera_init(const char *device, uint64_t caps, unsigned widt
245255
246256 if (num_sources < 0 )
247257 {
248- RARCH_ERR ("[FFMPEG] Failed to list video input sources: %s.\n" , av_err2str (num_sources ));
258+ char msg [AV_ERROR_MAX_STRING_SIZE ];
259+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , num_sources );
260+ RARCH_ERR ("[FFMPEG] Failed to list video input sources: %s.\n" , msg );
249261 goto error ;
250262 }
251263
@@ -263,7 +275,7 @@ static void *ffmpeg_camera_init(const char *device, uint64_t caps, unsigned widt
263275static void ffmpeg_camera_stop (void * data );
264276static void ffmpeg_camera_free (void * data )
265277{
266- ffmpeg_camera_t * ffmpeg = data ;
278+ ffmpeg_camera_t * ffmpeg = ( ffmpeg_camera_t * ) data ;
267279
268280 if (!ffmpeg )
269281 return ;
@@ -279,16 +291,17 @@ static void ffmpeg_camera_poll_thread(void *data);
279291
280292static bool ffmpeg_camera_start (void * data )
281293{
282- ffmpeg_camera_t * ffmpeg = data ;
283- int result = 0 ;
284- AVStream * stream = NULL ;
285- AVDictionary * options = NULL ;
294+ const AVDictionaryEntry * prev = NULL ;
295+ ffmpeg_camera_t * ffmpeg = (ffmpeg_camera_t * )data ;
296+ int result = 0 ;
297+ AVStream * stream = NULL ;
298+ AVDictionary * options = NULL ;
286299 const AVDictionaryEntry * e = NULL ;
287- const AVDictionaryEntry prev ;
288- int target_buffer_length = 0 ;
300+ int target_buffer_length = 0 ;
289301
302+ /* TODO: Check the actual format context, not just the pointer */
290303 if (ffmpeg -> format_context )
291- { // TODO: Check the actual format context, not just the pointer
304+ {
292305 RARCH_LOG ("[FFMPEG] Camera %s is already started, no action needed.\n" , ffmpeg -> format_context -> url );
293306 return true;
294307 }
@@ -300,18 +313,22 @@ static bool ffmpeg_camera_start(void *data)
300313 result = av_dict_copy (& options , ffmpeg -> options , 0 );
301314 if (result < 0 )
302315 {
303- RARCH_ERR ("[FFMPEG] Failed to copy options: %s.\n" , av_err2str (result ));
316+ char msg [AV_ERROR_MAX_STRING_SIZE ];
317+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
318+ RARCH_ERR ("[FFMPEG] Failed to copy options: %s.\n" , msg );
304319 goto error ;
305320 }
306321
307322 result = avformat_find_stream_info (ffmpeg -> format_context , & options );
308323 if (result < 0 )
309324 {
310- RARCH_ERR ("[FFMPEG] Failed to find stream info: %s.\n" , av_err2str (result ));
325+ char msg [AV_ERROR_MAX_STRING_SIZE ];
326+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
327+ RARCH_ERR ("[FFMPEG] Failed to find stream info: %s.\n" , msg );
311328 goto error ;
312329 }
313330
314- while ((e = av_dict_get (options , "" , & prev , AV_DICT_IGNORE_SUFFIX )))
331+ while ((e = av_dict_get (options , "" , prev , AV_DICT_IGNORE_SUFFIX )))
315332 {
316333 RARCH_WARN ("[FFMPEG] Unrecognized option on video input device: %s=%s.\n" , e -> key , e -> value );
317334 }
@@ -320,7 +337,9 @@ static bool ffmpeg_camera_start(void *data)
320337 AVMEDIA_TYPE_VIDEO , -1 , -1 , & ffmpeg -> decoder , 0 );
321338 if (result < 0 )
322339 {
323- RARCH_ERR ("[FFMPEG] Failed to find video stream: %s.\n" , av_err2str (result ));
340+ char msg [AV_ERROR_MAX_STRING_SIZE ];
341+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
342+ RARCH_ERR ("[FFMPEG] Failed to find video stream: %s.\n" , msg );
324343 goto error ;
325344 }
326345 stream = ffmpeg -> format_context -> streams [result ];
@@ -337,7 +356,9 @@ static bool ffmpeg_camera_start(void *data)
337356 result = avcodec_parameters_to_context (ffmpeg -> decoder_context , stream -> codecpar );
338357 if (result < 0 )
339358 {
340- RARCH_ERR ("[FFMPEG] Failed to copy codec parameters to decoder context: %s.\n" , av_err2str (result ));
359+ char msg [AV_ERROR_MAX_STRING_SIZE ];
360+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
361+ RARCH_ERR ("[FFMPEG] Failed to copy codec parameters to decoder context: %s.\n" , msg );
341362 goto error ;
342363 }
343364
@@ -350,18 +371,22 @@ static bool ffmpeg_camera_start(void *data)
350371 result = av_dict_copy (& ffmpeg -> options , options , 0 );
351372 if (result < 0 )
352373 {
353- RARCH_ERR ("[FFMPEG] Failed to copy options: %s.\n" , av_err2str (result ));
374+ char msg [AV_ERROR_MAX_STRING_SIZE ];
375+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
376+ RARCH_ERR ("[FFMPEG] Failed to copy options: %s.\n" , msg );
354377 goto error ;
355378 }
356379
357380 result = avcodec_open2 (ffmpeg -> decoder_context , ffmpeg -> decoder , & options );
358381 if (result < 0 )
359382 {
360- RARCH_ERR ("[FFMPEG] Failed to open decoder: %s.\n" , av_err2str (result ));
383+ char msg [AV_ERROR_MAX_STRING_SIZE ];
384+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
385+ RARCH_ERR ("[FFMPEG] Failed to open decoder: %s.\n" , msg );
361386 goto error ;
362387 }
363388
364- while ((e = av_dict_get (options , "" , & prev , AV_DICT_IGNORE_SUFFIX )))
389+ while ((e = av_dict_get (options , "" , prev , AV_DICT_IGNORE_SUFFIX )))
365390 {
366391 RARCH_WARN ("[FFMPEG] Unrecognized option on video input device: %s=%s.\n" , e -> key , e -> value );
367392 }
@@ -395,14 +420,16 @@ static bool ffmpeg_camera_start(void *data)
395420 );
396421 if (target_buffer_length < 0 )
397422 {
398- RARCH_ERR ("[FFMPEG] Failed to allocate target plane: %s.\n" , av_err2str (target_buffer_length ));
423+ char msg [AV_ERROR_MAX_STRING_SIZE ];
424+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , target_buffer_length );
425+ RARCH_ERR ("[FFMPEG] Failed to allocate target plane: %s.\n" , msg );
399426 goto error ;
400427 }
401428
402429 /* target buffer aligned to 4 bytes because it's exposed to the core as a uint32_t[] */
403430 ffmpeg -> target_buffer_length = target_buffer_length ;
404- ffmpeg -> target_buffers [0 ] = memalign_alloc (4 , target_buffer_length );
405- ffmpeg -> target_buffers [1 ] = memalign_alloc (4 , target_buffer_length );
431+ ffmpeg -> target_buffers [0 ] = ( uint8_t * ) memalign_alloc (4 , target_buffer_length );
432+ ffmpeg -> target_buffers [1 ] = ( uint8_t * ) memalign_alloc (4 , target_buffer_length );
406433 ffmpeg -> active_buffer = ffmpeg -> target_buffers [0 ];
407434 if (!ffmpeg -> target_buffers [0 ] || !ffmpeg -> target_buffers [1 ])
408435 {
@@ -461,7 +488,7 @@ static bool ffmpeg_camera_start(void *data)
461488
462489static void ffmpeg_camera_stop (void * data )
463490{
464- ffmpeg_camera_t * ffmpeg = data ;
491+ ffmpeg_camera_t * ffmpeg = ( ffmpeg_camera_t * ) data ;
465492
466493 if (!ffmpeg -> format_context )
467494 {
@@ -472,7 +499,9 @@ static void ffmpeg_camera_stop(void *data)
472499 int result = avcodec_send_packet (ffmpeg -> decoder_context , NULL );
473500 if (result < 0 )
474501 {
475- RARCH_ERR ("[FFMPEG] Failed to flush decoder: %s.\n" , av_err2str (result ));
502+ char msg [AV_ERROR_MAX_STRING_SIZE ];
503+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
504+ RARCH_ERR ("[FFMPEG] Failed to flush decoder: %s.\n" , msg );
476505 }
477506 }
478507
@@ -508,17 +537,20 @@ static void ffmpeg_camera_stop(void *data)
508537
509538static void ffmpeg_camera_poll_thread (void * data )
510539{
511- ffmpeg_camera_t * ffmpeg = data ;
540+ ffmpeg_camera_t * ffmpeg = ( ffmpeg_camera_t * ) data ;
512541
513542 if (!ffmpeg )
514543 return ;
515544
516545 while (!ffmpeg -> done )
517546 {
518547 int result = av_read_frame (ffmpeg -> format_context , ffmpeg -> packet );
548+ /* Read the raw data from the camera. If that fails... */
519549 if (result < 0 )
520- { /* Read the raw data from the camera. If that fails... */
521- RARCH_ERR ("[FFMPEG] Failed to read frame: %s.\n" , av_err2str (result ));
550+ {
551+ char msg [AV_ERROR_MAX_STRING_SIZE ];
552+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
553+ RARCH_ERR ("[FFMPEG] Failed to read frame: %s.\n" , msg );
522554 continue ;
523555 }
524556
@@ -531,19 +563,26 @@ static void ffmpeg_camera_poll_thread(void *data)
531563 }
532564 else
533565 {
534- RARCH_ERR ("[FFMPEG] Failed to send packet to decoder: %s.\n" , av_err2str (result ));
566+ char msg [AV_ERROR_MAX_STRING_SIZE ];
567+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
568+ RARCH_ERR ("[FFMPEG] Failed to send packet to decoder: %s.\n" , msg );
535569 }
536570
537571 goto done_loop ;
538572 }
539573
540574 /* video streams consist of exactly one frame per packet */
541575 result = avcodec_receive_frame (ffmpeg -> decoder_context , ffmpeg -> camera_frame );
576+
577+ /* Send the decoded data to the camera frame. If that fails... */
542578 if (result < 0 )
543- { /* Send the decoded data to the camera frame. If that fails... */
579+ {
580+ /* These error codes mean no new frame, but not necessarily a problem */
544581 if (!(result == AVERROR_EOF || result == AVERROR (EAGAIN )))
545- { /* these error codes mean no new frame, but not necessarily a problem */
546- RARCH_ERR ("[FFMPEG] Failed to receive camera frame from decoder: %s.\n" , av_err2str (result ));
582+ {
583+ char msg [AV_ERROR_MAX_STRING_SIZE ];
584+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
585+ RARCH_ERR ("[FFMPEG] Failed to receive camera frame from decoder: %s.\n" , msg );
547586 }
548587
549588 goto done_loop ;
@@ -561,9 +600,13 @@ static void ffmpeg_camera_poll_thread(void *data)
561600 ffmpeg -> target_planes ,
562601 ffmpeg -> target_linesizes
563602 );
603+
604+ /* Scale and convert the frame to the target format. If that fails... */
564605 if (result < 0 )
565- { /* Scale and convert the frame to the target format. If that fails... */
566- RARCH_ERR ("[FFMPEG] Failed to scale frame: %s.\n" , av_err2str (result ));
606+ {
607+ char msg [AV_ERROR_MAX_STRING_SIZE ];
608+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
609+ RARCH_ERR ("[FFMPEG] Failed to scale frame: %s.\n" , msg );
567610 goto done_loop ;
568611 }
569612
@@ -583,7 +626,9 @@ static void ffmpeg_camera_poll_thread(void *data)
583626 slock_unlock (ffmpeg -> target_buffer_lock );
584627 if (result < 0 )
585628 {
586- RARCH_ERR ("[FFMPEG] Failed to copy frame to buffer: %s.\n" , av_err2str (result ));
629+ char msg [AV_ERROR_MAX_STRING_SIZE ];
630+ av_make_error_string (msg , AV_ERROR_MAX_STRING_SIZE , result );
631+ RARCH_ERR ("[FFMPEG] Failed to copy frame to buffer: %s.\n" , msg );
587632 goto done_loop ;
588633 }
589634 done_loop :
@@ -595,12 +640,11 @@ static void ffmpeg_camera_poll_thread(void *data)
595640 av_packet_unref (ffmpeg -> packet );
596641}
597642
598- static bool ffmpeg_camera_poll (
599- void * data ,
643+ static bool ffmpeg_camera_poll (void * data ,
600644 retro_camera_frame_raw_framebuffer_t frame_raw_cb ,
601645 retro_camera_frame_opengl_texture_t frame_gl_cb )
602646{
603- ffmpeg_camera_t * ffmpeg = data ;
647+ ffmpeg_camera_t * ffmpeg = ( ffmpeg_camera_t * ) data ;
604648
605649 if (!ffmpeg -> format_context )
606650 {
0 commit comments