2424#include " ffaudio-stdinc.h"
2525
2626#include < limits.h>
27- #include < pthread.h>
2827
2928#include < audacious/audtag.h>
3029#include < libaudcore/audstrings.h>
3130#include < libaudcore/i18n.h>
3231#include < libaudcore/multihash.h>
3332#include < libaudcore/runtime.h>
3433
35- #if CHECK_LIBAVFORMAT_VERSION (57, 33, 100)
36- #define ALLOC_CONTEXT 1
37- #endif
38-
39- #if CHECK_LIBAVCODEC_VERSION (57, 37, 100)
40- #define SEND_PACKET 1
41- #endif
42-
4334class FFaudio : public InputPlugin
4435{
4536public:
@@ -83,33 +74,19 @@ struct ScopedContext
8374
8475 ScopedContext (const CodecInfo & cinfo)
8576 {
86- #ifdef ALLOC_CONTEXT
8777 ptr = avcodec_alloc_context3 (cinfo.codec );
8878 avcodec_parameters_to_context (ptr, cinfo.stream ->codecpar );
89- #else
90- ptr = cinfo.stream ->codec ;
91- #endif
92-
93- #if CHECK_LIBAVCODEC_VERSION(58, 9, 100)
9479 ptr->pkt_timebase = cinfo.stream ->time_base ;
95- #else
96- av_codec_set_pkt_timebase (ptr, cinfo.stream ->time_base );
97- #endif
9880 }
9981
100- #ifdef ALLOC_CONTEXT
10182 ~ScopedContext () { avcodec_free_context (& ptr); }
102- #else
103- ~ScopedContext () { avcodec_close (ptr); }
104- #endif
10583};
10684
10785struct ScopedPacket
10886{
10987 AVPacket * ptr;
11088 AVPacket * operator -> () { return ptr; }
11189
112- #if CHECK_LIBAVCODEC_VERSION(57, 12, 100)
11390 ScopedPacket () { ptr = av_packet_alloc (); }
11491 ~ScopedPacket () { av_packet_free (& ptr); }
11592
@@ -118,26 +95,6 @@ struct ScopedPacket
11895 av_packet_free (& ptr);
11996 ptr = av_packet_alloc ();
12097 }
121- #else
122- ScopedPacket ()
123- {
124- ptr = new AVPacket ();
125- av_init_packet (ptr);
126- }
127-
128- ~ScopedPacket ()
129- {
130- av_packet_unref (ptr);
131- delete ptr;
132- }
133-
134- void clear ()
135- {
136- av_packet_unref (ptr);
137- * ptr = AVPacket ();
138- av_init_packet (ptr);
139- }
140- #endif
14198};
14299
143100struct ScopedFrame
@@ -151,31 +108,6 @@ static SimpleHash<String, AVInputFormat *> extension_dict;
151108
152109static void create_extension_dict ();
153110
154- #if ! CHECK_LIBAVCODEC_VERSION(58, 9, 100)
155- static int lockmgr (void * * mutexp, enum AVLockOp op)
156- {
157- switch (op)
158- {
159- case AV_LOCK_CREATE:
160- * mutexp = new pthread_mutex_t ;
161- pthread_mutex_init ((pthread_mutex_t *) * mutexp, nullptr );
162- break ;
163- case AV_LOCK_OBTAIN:
164- pthread_mutex_lock ((pthread_mutex_t *) * mutexp);
165- break ;
166- case AV_LOCK_RELEASE:
167- pthread_mutex_unlock ((pthread_mutex_t *) * mutexp);
168- break ;
169- case AV_LOCK_DESTROY:
170- pthread_mutex_destroy ((pthread_mutex_t *) * mutexp);
171- delete (pthread_mutex_t *) * mutexp;
172- break ;
173- }
174-
175- return 0 ;
176- }
177- #endif
178-
179111static void ffaudio_log_cb (void * avcl, int av_level, const char * fmt, va_list va)
180112{
181113 audlog::Level level = audlog::Debug;
@@ -210,27 +142,14 @@ static void ffaudio_log_cb (void * avcl, int av_level, const char * fmt, va_list
210142
211143bool FFaudio::init ()
212144{
213- #if ! CHECK_LIBAVFORMAT_VERSION(58, 9, 100)
214- av_register_all ();
215- #endif
216- #if ! CHECK_LIBAVCODEC_VERSION(58, 9, 100)
217- av_lockmgr_register (lockmgr);
218- #endif
219-
220145 create_extension_dict ();
221-
222146 av_log_set_callback (ffaudio_log_cb);
223-
224147 return true ;
225148}
226149
227150void FFaudio::cleanup ()
228151{
229152 extension_dict.clear ();
230-
231- #if ! CHECK_LIBAVCODEC_VERSION(58, 9, 100)
232- av_lockmgr_register (nullptr );
233- #endif
234153}
235154
236155static int log_result (const char * func, int ret)
@@ -252,12 +171,8 @@ static int log_result (const char * func, int ret)
252171static void create_extension_dict ()
253172{
254173 AVInputFormat * f;
255- #if CHECK_LIBAVFORMAT_VERSION(58, 9, 100)
256174 void * iter = nullptr ;
257175 while ((f = const_cast <AVInputFormat *> (av_demuxer_iterate (& iter))))
258- #else
259- for (f = av_iformat_next (nullptr ); f; f = av_iformat_next (f))
260- #endif
261176 {
262177 if (! f->extensions )
263178 continue ;
@@ -380,9 +295,6 @@ static bool find_codec (AVFormatContext * c, CodecInfo * cinfo)
380295 {
381296 AVStream * stream = c->streams [i];
382297
383- #ifndef ALLOC_CONTEXT
384- #define codecpar codec
385- #endif
386298 if (stream && stream->codecpar && stream->codecpar ->codec_type == AVMEDIA_TYPE_AUDIO)
387299 {
388300 AVCodec * codec = (AVCodec *) avcodec_find_decoder (stream->codecpar ->codec_id );
@@ -396,7 +308,6 @@ static bool find_codec (AVFormatContext * c, CodecInfo * cinfo)
396308 return true ;
397309 }
398310 }
399- #undef codecpar
400311 }
401312
402313 return false ;
@@ -605,39 +516,15 @@ bool FFaudio::play (const char * filename, VFSFile & file)
605516 }
606517
607518 /* Decode and play packet/frame */
608- #ifdef SEND_PACKET
609519 if (LOG (avcodec_send_packet, context.ptr , pkt.ptr ) < 0 )
610520 return false ; /* defensive, errors not expected here */
611- #else
612- /* Make a mutable (shallow) copy of the real packet */
613- AVPacket tmp = * pkt.ptr ;
614- #endif
615521
616522 while (! check_stop ())
617523 {
618524 ScopedFrame frame;
619525
620- #ifdef SEND_PACKET
621526 if (LOG (avcodec_receive_frame, context.ptr , frame.ptr ) < 0 )
622527 break ; /* read next packet (continue past errors) */
623- #else
624- int decoded = 0 ;
625- int len = LOG (avcodec_decode_audio4, context.ptr , frame.ptr , & decoded, & tmp);
626-
627- if (len < 0 )
628- break ; /* read next packet (continue past errors) */
629-
630- tmp.size -= len;
631- tmp.data += len;
632-
633- if (! decoded)
634- {
635- if (tmp.size > 0 )
636- continue ; /* process more of current packet */
637-
638- break ; /* read next packet */
639- }
640- #endif
641528
642529 int size = FMT_SIZEOF (out_fmt) * channels * frame->nb_samples ;
643530
0 commit comments