summaryrefslogtreecommitdiffstats
path: root/media-plugins/xmms-wma/files/xmms-wma-ds-ffmpeg20081014.patch
blob: 23c0b1a43220229d6c06eb84ec9779e1d1d1ba92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
diff -dPNur xmms-wma-1.0.5/Makefile xmms-wma-1.0.5-ds/Makefile
--- xmms-wma-1.0.5/Makefile	2004-03-03 15:47:58.000000000 +0100
+++ xmms-wma-1.0.5-ds/Makefile	2008-11-27 01:33:03.000000000 +0100
@@ -11,7 +11,7 @@
 export DEPS := $(SOURCES:%.c=$(DEPDIR)/%.d)
 
 all:
-	@cd ffmpeg-strip-wma; make; cd ..
+	#@cd ffmpeg-strip-wma; make; cd ..
 	@$(MAKE) --no-print-directory -f Makefile.inc
 	@strip $(PLUGIN_FILE)
 	@echo "The plug-in has been compiled. Run one of the following:"
@@ -40,5 +40,5 @@
 	@echo "The plug-in has been uninstalled."
 
 clean:
-	cd ffmpeg-strip-wma; make clean; cd ..
+	#cd ffmpeg-strip-wma; make clean; cd ..
 	rm -f $(OBJECTS) $(DEPS)
diff -dPNur xmms-wma-1.0.5/Makefile.inc xmms-wma-1.0.5-ds/Makefile.inc
--- xmms-wma-1.0.5/Makefile.inc	2005-09-05 14:48:20.000000000 +0200
+++ xmms-wma-1.0.5-ds/Makefile.inc	2008-11-27 01:35:01.000000000 +0100
@@ -1,16 +1,18 @@
 CC := gcc
-CFLAGS := -O2 -ffast-math -fomit-frame-pointer -fPIC
-#CFLAGS := -Wall -g -O3
-CFLAGS += -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE
-CFLAGS += -I ffmpeg-strip-wma
-CFLAGS += `xmms-config --cflags`
-LIBS := `xmms-config --libs` -L ffmpeg-strip-wma -lffwma
+MYCFLAGS := $(CFLAGS) -fPIC
+#MYCFLAGS := -Wall -g -O3
+MYCFLAGS += -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -fPIC
+#MYCFLAGS += -I ffmpeg-strip-wma
+MYCFLAGS += `xmms-config --cflags`
+MYCFLAGS += -I/usr/include/ffmpeg
+#LIBS := `xmms-config --libs` -L ffmpeg-strip-wma -lffwma
+LIBS := `xmms-config --libs` -lavcodec -lavformat
 
 $(PLUGIN_FILE): $(OBJECTS)
 	$(CC) -o $@ $^ $(LIBS) -shared
 
 $(OBJDIR)/%.o: %.c
-	$(CC) -c -o $@ $(CFLAGS) $<
+	$(CC) -c -o $@ $(MYCFLAGS) $<
 
 $(DEPDIR)/%.d: %.c
 	$(CC) -MM $(CFLAGS) $< | sed "s/^$*\.o:/$(OBJDIR)\/$*\.o $(DEPDIR)\/$*\.d:/" > $@
diff -dPNur xmms-wma-1.0.5/xmms-wma.c xmms-wma-1.0.5-ds/xmms-wma.c
--- xmms-wma-1.0.5/xmms-wma.c	2008-11-27 02:58:02.000000000 +0100
+++ xmms-wma-1.0.5-ds/xmms-wma.c	2008-11-27 02:54:38.000000000 +0100
@@ -43,8 +43,9 @@
 #undef HAVE_AV_CONFIG_H
 #endif
 
-#include "avcodec.h"
-#include "avformat.h"
+#include "libavcodec/avcodec.h"
+#include "libavformat/avformat.h"
+#include "libavutil/fifo.h"
 #include "iir.h"
 
 #define ABOUT_TXT "Copyright (C) 2004,2005 Mokrushin I.V. aka McMCC (mcmcc@mail.ru).\n \
@@ -191,8 +192,6 @@
 
 static void wma_init(void)
 {
-    avcodec_init();
-    avcodec_register_all();
     av_register_all();
     init_iir();
 }
@@ -201,9 +200,14 @@
 {
     gchar *ext;
     ext = strrchr(filename, '.');
-    if(ext)
+    if(ext) {
         if(!strcasecmp(ext, ".wma"))
             return 1;
+        if(!strcasecmp(ext, ".m4a"))
+            return 1;
+        if(!strcasecmp(ext, ".aac"))
+            return 1;
+    }
     return 0;
 }
 
@@ -338,21 +342,23 @@
 	return;
 #endif
 	
-    av_find_stream_info(in);
-    (*len_real) = get_song_time(in);
-    (*title_real) = get_song_title(in, filename);
+    if (!av_find_stream_info(in)) {
+	(*len_real) = get_song_time(in);
+	(*title_real) = get_song_title(in, filename);
+    }
     av_close_input_file(in);
 }
-
 static void wma_playbuff(int out_size)
 {
-    FifoBuffer f;
+    AVFifoBuffer f;
     int sst_buff;
-    
-    fifo_init(&f, out_size*2);
-    fifo_write(&f, wma_outbuf, out_size, &f.wptr);
-    while(!fifo_read(&f, wma_s_outbuf, wma_st_buff, &f.rptr) && wma_decode)
-    {
+
+    av_fifo_init(&f, out_size*2);
+    av_fifo_generic_write(&f, wma_outbuf, out_size, NULL);
+
+    while ((av_fifo_size(&f) > 0) && wma_decode) {
+	if (av_fifo_read(&f, wma_s_outbuf, wma_st_buff)) break;
+	
         if(wma_eq_on)
             sst_buff = iir((gpointer)&wma_s_outbuf, wma_st_buff);
         else
@@ -365,7 +371,7 @@
 	wma_ip.output->write_audio((short *)wma_s_outbuf, sst_buff);
 	memset(wma_s_outbuf, 0, sst_buff);
     }
-    fifo_free(&f);
+    av_fifo_free(&f);
     return;
 }
 
@@ -374,18 +380,29 @@
     uint8_t *inbuf_ptr;
     int out_size, size, len;
     AVPacket pkt;
+    int64_t seek_target;
     
     pthread_mutex_lock(&wma_mutex);
     while(wma_decode){
-
 	if(wma_seekpos != -1)
 	{
-	    av_seek_frame(ic, wma_idx, wma_seekpos * 1000000LL);
+	    if (wma_idx>=0) {
+		seek_target = av_rescale_q(wma_seekpos * 1000000LL, AV_TIME_BASE_Q, ic->streams[wma_idx]->time_base);
+	    } else {
+		seek_target = wma_seekpos * 1000000LL;
+	    }
+	    av_seek_frame(ic, wma_idx, seek_target, AVSEEK_FLAG_BACKWARD);
 	    wma_ip.output->flush(wma_seekpos * 1000);
 	    wma_seekpos = -1;
 	}
 
-        if(av_read_frame(ic, &pkt) < 0) break;
+        if(av_read_frame(ic, &pkt) < 0) {
+	    /*if (url_ferror(&ic->pb) == 0) {
+		usleep(100000);
+		continue;
+	    }*/
+	    break;
+	}
 
         size = pkt.size;
         inbuf_ptr = pkt.data;
@@ -393,7 +410,9 @@
         if(size == 0) break;
 	
         while(size > 0){
-            len = avcodec_decode_audio(c, (short *)wma_outbuf, &out_size,
+	    out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
+	    
+            len = avcodec_decode_audio2(c, (short *)wma_outbuf, &out_size,
                                        inbuf_ptr, size);
 	    if(len < 0) break;
 	    
@@ -428,10 +447,13 @@
 #endif
     
     for(wma_idx = 0; wma_idx < ic->nb_streams; wma_idx++) {
-        c = &ic->streams[wma_idx]->codec;
+        c = ic->streams[wma_idx]->codec;
         if(c->codec_type == CODEC_TYPE_AUDIO) break;
     }
 
+    if(!c || c->codec_type != CODEC_TYPE_AUDIO)
+	    return;
+
     av_find_stream_info(ic);
 
     codec = avcodec_find_decoder(c->codec_id);
@@ -460,7 +482,8 @@
 {
     wma_decode = 0;
     if(wma_pause) wma_do_pause(0);
-    pthread_join(wma_decode_thread, NULL);
+    if(wma_decode_thread)
+	    pthread_join(wma_decode_thread, NULL);
     wma_ip.output->close_audio();
 }	
 
@@ -484,7 +507,7 @@
 #endif
 
     for(i = 0; i < in->nb_streams; i++) {
-        s = &in->streams[i]->codec;
+        s = in->streams[i]->codec;
         if(s->codec_type == CODEC_TYPE_AUDIO) break;
     }