Package list squeezelite / 2721ed7
only load ffmpeg .so which matches header file version Adrian Smith 8 years ago
2 changed file(s) with 12 addition(s) and 40 deletion(s). Raw diff Collapse all Expand all
2424 #include <libavformat/avformat.h>
2525 #include <libavcodec/avcodec.h>
2626
27 // we try to load a range of ffmpeg library versions
28 // note that this file must be compiled with header files of the same major version as the library loaded
29 // (as structs accessed may change between major versions)
30
3127 #define LIBAVUTIL "libavutil.so"
32 #define LIBAVUTIL_MAX 52
33 #define LIBAVUTIL_MIN 51
34
3528 #define LIBAVCODEC "libavcodec.so"
36 #define LIBAVCODEC_MAX 55
37 #define LIBAVCODEC_MIN 53
38
3929 #define LIBAVFORMAT "libavformat.so"
40 #define LIBAVFORMAT_MAX 55
41 #define LIBAVFORMAT_MIN 53
4230
4331
4432 #define READ_SIZE 4096 * 4 // this is large enough to ensure ffmpeg always gets new data when decode is called
573561 void *handle_codec = NULL, *handle_format = NULL, *handle_util = NULL;
574562 char name[30];
575563 char *err;
576 int i;
577
578 // attempt to load newest known versions of libraries first
579 for (i = LIBAVCODEC_MAX; i >= LIBAVCODEC_MIN && !handle_codec; --i) {
580 sprintf(name, "%s.%d", LIBAVCODEC, i);
581 handle_codec = dlopen(name, RTLD_NOW);
582 }
564
565 // we try to load the ffmpeg library version which matches the header file we are compiled with as structs differ between versions
566
567 sprintf(name, "%s.%d", LIBAVCODEC, LIBAVCODEC_VERSION_MAJOR);
568 handle_codec = dlopen(name, RTLD_NOW);
583569 if (!handle_codec) {
584570 LOG_INFO("dlerror: %s", dlerror());
585571 return false;
586572 }
587573
588 for (i = LIBAVFORMAT_MAX; i >= LIBAVFORMAT_MIN && !handle_format; --i) {
589 sprintf(name, "%s.%d", LIBAVFORMAT, i);
590 handle_format = dlopen(name, RTLD_NOW);
591 }
574 sprintf(name, "%s.%d", LIBAVFORMAT, LIBAVFORMAT_VERSION_MAJOR);
575 handle_format = dlopen(name, RTLD_NOW);
592576 if (!handle_format) {
593577 LOG_INFO("dlerror: %s", dlerror());
594578 return false;
595579 }
596580
597 for (i = LIBAVUTIL_MAX; i >= LIBAVUTIL_MIN && !handle_util; --i) {
598 sprintf(name, "%s.%d", LIBAVUTIL, i);
599 handle_util = dlopen(name, RTLD_NOW);
600 }
581 sprintf(name, "%s.%d", LIBAVUTIL, LIBAVUTIL_VERSION_MAJOR);
582 handle_util = dlopen(name, RTLD_NOW);
601583 if (!handle_util) {
602584 LOG_INFO("dlerror: %s", dlerror());
603585 return false;
620602
621603 ff->avcodec_v = ff->avcodec_version();
622604 LOG_INFO("loaded "LIBAVCODEC" (%u.%u.%u)", ff->avcodec_v >> 16, (ff->avcodec_v >> 8) & 0xff, ff->avcodec_v & 0xff);
623 if (ff->avcodec_v >> 16 != LIBAVCODEC_VERSION_MAJOR) {
624 LOG_WARN("error: library major version (%u) differs from build headers (%u)", ff->avcodec_v >> 16, LIBAVCODEC_VERSION_MAJOR);
625 return false;
626 }
627605
628606 ff->avformat_version = dlsym(handle_format, "avformat_version");
629607 ff->avformat_alloc_context = dlsym(handle_format, "avformat_alloc_context");
644622
645623 ff->avformat_v = ff->avformat_version();
646624 LOG_INFO("loaded "LIBAVFORMAT" (%u.%u.%u)", ff->avformat_v >> 16, (ff->avformat_v >> 8) & 0xff, ff->avformat_v & 0xff);
647 if (ff->avformat_v >> 16 != LIBAVFORMAT_VERSION_MAJOR) {
648 LOG_WARN("error: library major version (%u) differs from build headers (%u)", ff->avformat_v >> 16, LIBAVFORMAT_VERSION_MAJOR);
649 return false;
650 }
651625
652626 ff->avutil_version = dlsym(handle_util, "avutil_version");
653627 ff->av_log_set_callback = dlsym(handle_util, "av_log_set_callback");
663637
664638 ff->avutil_v = ff->avutil_version();
665639 LOG_INFO("loaded "LIBAVUTIL" (%u.%u.%u)", ff->avutil_v >> 16, (ff->avutil_v >> 8) & 0xff, ff->avutil_v & 0xff);
666 if (ff->avutil_v >> 16 != LIBAVUTIL_VERSION_MAJOR) {
667 LOG_WARN("error: library major version (%u) differs from build headers (%u)", ff->avutil_v >> 16, LIBAVUTIL_VERSION_MAJOR);
668 return false;
669 }
670640
671641 return true;
672642 }
14921492 buf_flush(outputbuf);
14931493 LOCK;
14941494 output.fade = FADE_INACTIVE;
1495 output.state = OUTPUT_STOPPED;
1495 if (output.state != OUTPUT_OFF) {
1496 output.state = OUTPUT_STOPPED;
1497 }
14961498 output.frames_played = 0;
14971499 UNLOCK;
14981500 }