Lines 10-24
Link Here
|
10 |
// |
10 |
// |
11 |
// |
11 |
// |
12 |
#include "k9avidecode.h" |
12 |
#include "k9avidecode.h" |
13 |
#include <avcodec.h> |
|
|
14 |
#include <qimage.h> |
13 |
#include <qimage.h> |
15 |
#include <dlfcn.h> |
14 |
#include <dlfcn.h> |
16 |
#include "k9common.h" |
15 |
#include "k9common.h" |
17 |
|
16 |
|
18 |
#ifdef HAVE_SWSCALE |
17 |
#ifdef HAVE_SWSCALE |
19 |
|
18 |
|
20 |
#include "swscale.h" |
|
|
21 |
|
22 |
static int sws_flags = SWS_BICUBIC; |
19 |
static int sws_flags = SWS_BICUBIC; |
23 |
|
20 |
|
24 |
#endif |
21 |
#endif |
Lines 35-101
Link Here
|
35 |
|
32 |
|
36 |
k9AviDecode::k9AviDecode(QObject *parent, const char *) |
33 |
k9AviDecode::k9AviDecode(QObject *parent, const char *) |
37 |
: QObject(parent) { |
34 |
: QObject(parent) { |
38 |
CodecHandle=0; |
|
|
39 |
FormatHandle=0; |
40 |
SwscaleHandle=0; |
41 |
glibref=0; |
42 |
if (glibref==0) { |
43 |
CodecHandle=dlopen("libavcodec.so",RTLD_LAZY ); //| RTLD_GLOBAL |
44 |
FormatHandle=dlopen("libavformat.so",RTLD_LAZY); |
45 |
#ifdef HAVE_SWSCALE |
46 |
SwscaleHandle=dlopen("libswscale.so",RTLD_LAZY); |
47 |
if (SwscaleHandle==0) |
48 |
SwscaleHandle=dlopen("libswscale.so.2",RTLD_LAZY); |
49 |
#endif |
50 |
} |
51 |
m_error=""; |
35 |
m_error=""; |
52 |
QStringList errs; |
36 |
QStringList errs; |
53 |
if (!CodecHandle) { |
|
|
54 |
errs << i18n("Cannot open the library %1").arg("libavcodec"); |
55 |
} |
56 |
if (!FormatHandle ) { |
57 |
errs << i18n("Cannot open the library %1").arg("libavformat"); |
58 |
} |
59 |
#ifdef HAVE_SWSCALE |
60 |
if (!SwscaleHandle) { |
61 |
errs << i18n("Cannot open the library %1").arg("libswscale"); |
62 |
} |
63 |
#endif |
64 |
|
65 |
av_register_all = (av_register_all_t)dlsym(FormatHandle,"av_register_all"); |
66 |
av_open_input_file = (av_open_input_file_t)dlsym(FormatHandle,"av_open_input_file"); |
67 |
av_find_stream_info = (av_find_stream_info_t)dlsym(FormatHandle,"av_find_stream_info"); |
68 |
avcodec_find_decoder =(avcodec_find_decoder_t) dlsym(CodecHandle,"avcodec_find_decoder"); |
69 |
avcodec_open = (avcodec_open_t)dlsym(CodecHandle,"avcodec_open"); |
70 |
avcodec_alloc_frame = (avcodec_alloc_frame_t)dlsym(CodecHandle,"avcodec_alloc_frame"); |
71 |
avpicture_get_size = (avpicture_get_size_t)dlsym(CodecHandle,"avpicture_get_size"); |
72 |
av_malloc = (av_malloc_t)dlsym(CodecHandle,"av_malloc"); |
73 |
avpicture_fill = (avpicture_fill_t)dlsym(CodecHandle,"avpicture_fill"); |
74 |
av_read_frame = (av_read_frame_t)dlsym(FormatHandle,"av_read_frame"); |
75 |
avcodec_decode_video = (avcodec_decode_video_t)dlsym(CodecHandle,"avcodec_decode_video"); |
76 |
if (avcodec_decode_video==0) avcodec_decode_video=(avcodec_decode_video_t)dlsym(CodecHandle,"avcodec_decode_video2"); |
77 |
#ifndef HAVE_SWSCALE |
78 |
img_convert = (img_convert_t)dlsym(CodecHandle,"img_convert"); |
79 |
//if img_convert is null (deprecated in ffmpeg), we need libswscale |
80 |
if (!img_convert) |
81 |
errs << i18n("Cannot open the library %1").arg("libswscale"); |
82 |
#endif |
83 |
av_free = (av_free_t)dlsym(CodecHandle,"av_free"); |
84 |
av_free_packet = (av_free_packet_t)dlsym(CodecHandle,"av_free_packet"); |
85 |
if (av_free_packet==0) |
86 |
av_free_packet=av_free_packet_internal; |
87 |
avcodec_close = (avcodec_close_t)dlsym(FormatHandle,"avcodec_close"); |
88 |
av_close_input_file = (av_close_input_file_t)dlsym(FormatHandle,"av_close_input_file"); |
89 |
av_seek_frame=(av_seek_frame_t)dlsym(FormatHandle,"av_seek_frame"); |
90 |
av_rescale_q=(av_rescale_q_t)dlsym(FormatHandle,"av_rescale_q"); |
91 |
avcodec_flush_buffers=(avcodec_flush_buffers_t)dlsym(CodecHandle,"avcodec_flush_buffers"); |
92 |
#ifdef HAVE_SWSCALE |
93 |
sws_freeContext= (sws_freeContext_t)dlsym(SwscaleHandle,"sws_freeContext"); |
94 |
sws_getContext=(sws_getContext_t)dlsym(SwscaleHandle,"sws_getContext"); |
95 |
sws_scale= (sws_scale_t)dlsym(SwscaleHandle,"sws_scale"); |
96 |
#endif |
97 |
av_gettime=(av_gettime_t)dlsym(FormatHandle,"av_gettime"); |
98 |
|
99 |
if (errs.count() >0) { |
37 |
if (errs.count() >0) { |
100 |
m_error=errs.join("\n"); |
38 |
m_error=errs.join("\n"); |
101 |
k9Dialogs::error(m_error,"k9copy",QStringList()); |
39 |
k9Dialogs::error(m_error,"k9copy",QStringList()); |
Lines 104-131
Link Here
|
104 |
|
42 |
|
105 |
av_register_all(); |
43 |
av_register_all(); |
106 |
m_opened=false; |
44 |
m_opened=false; |
107 |
|
|
|
108 |
glibref++; |
109 |
} |
45 |
} |
110 |
|
46 |
|
111 |
|
47 |
|
112 |
k9AviDecode::~k9AviDecode() { |
48 |
k9AviDecode::~k9AviDecode() { |
113 |
if (m_opened) |
49 |
if (m_opened) |
114 |
close(); |
50 |
close(); |
115 |
glibref--; |
|
|
116 |
if (glibref==0) { |
117 |
if (FormatHandle) |
118 |
dlclose(FormatHandle); |
119 |
if (CodecHandle) |
120 |
dlclose(CodecHandle); |
121 |
#ifdef HAVE_SWSCALE |
122 |
if (SwscaleHandle) |
123 |
dlclose(CodecHandle); |
124 |
#endif |
125 |
FormatHandle=0; |
126 |
CodecHandle=0; |
127 |
} |
128 |
|
129 |
} |
51 |
} |
130 |
|
52 |
|
131 |
bool k9AviDecode::open(const QString & _fileName) { |
53 |
bool k9AviDecode::open(const QString & _fileName) { |
Lines 134-145
Link Here
|
134 |
close(); |
56 |
close(); |
135 |
|
57 |
|
136 |
// Open video file |
58 |
// Open video file |
137 |
if (av_open_input_file(&m_FormatCtx, _fileName.toUtf8(), NULL, 0, NULL)!=0) { |
59 |
if (avformat_open_input(&m_FormatCtx, _fileName.toUtf8(), NULL, NULL)!=0) { |
138 |
m_error=i18n("Couldn't open the file %1").arg(_fileName); |
60 |
m_error=i18n("Couldn't open the file %1").arg(_fileName); |
139 |
return false; // Couldn't open file} |
61 |
return false; // Couldn't open file} |
140 |
} |
62 |
} |
141 |
// Retrieve stream information |
63 |
// Retrieve stream information |
142 |
if (av_find_stream_info(m_FormatCtx)<0) { |
64 |
if (avformat_find_stream_info(m_FormatCtx, NULL)<0) { |
143 |
m_error =i18n("Couldn't find stream information"); |
65 |
m_error =i18n("Couldn't find stream information"); |
144 |
return false; // Couldn't find stream information |
66 |
return false; // Couldn't find stream information |
145 |
} |
67 |
} |
Lines 168-174
Link Here
|
168 |
return false; // Codec not found |
90 |
return false; // Codec not found |
169 |
} |
91 |
} |
170 |
// Open codec |
92 |
// Open codec |
171 |
if (avcodec_open(m_CodecCtx, m_Codec)<0) { |
93 |
if (avcodec_open2(m_CodecCtx, m_Codec, NULL)<0) { |
172 |
m_error =i18n("Could'nt open the codec"); |
94 |
m_error =i18n("Could'nt open the codec"); |
173 |
return false; // Could not open codec |
95 |
return false; // Could not open codec |
174 |
} |
96 |
} |
Lines 245-259
Link Here
|
245 |
// Is this a packet from the video stream? |
167 |
// Is this a packet from the video stream? |
246 |
if (packet.stream_index==m_videoStream) { |
168 |
if (packet.stream_index==m_videoStream) { |
247 |
// Decode video frame |
169 |
// Decode video frame |
248 |
avcodec_decode_video(m_CodecCtx, m_Frame, &frameFinished, |
170 |
avcodec_decode_video2(m_CodecCtx, m_Frame, &frameFinished, |
249 |
packet.data, packet.size); |
171 |
&packet); |
250 |
|
172 |
|
251 |
// Did we get a video frame? |
173 |
// Did we get a video frame? |
252 |
if (frameFinished) { |
174 |
if (frameFinished) { |
253 |
// if (m_Frame->pts >=fspos) |
175 |
// if (m_Frame->pts >=fspos) |
254 |
int64_t cur_dts=fspos; |
176 |
int64_t cur_dts=fspos; |
255 |
if (m_FormatCtx->cur_st) |
177 |
cur_dts=packet.dts; |
256 |
cur_dts= m_FormatCtx->cur_st->cur_dts; |
|
|
257 |
if (cur_dts >=fspos) { |
178 |
if (cur_dts >=fspos) { |
258 |
bFound=true; |
179 |
bFound=true; |
259 |
#ifndef HAVE_SWSCALE |
180 |
#ifndef HAVE_SWSCALE |
Lines 309-315
Link Here
|
309 |
avcodec_close(m_CodecCtx); |
230 |
avcodec_close(m_CodecCtx); |
310 |
|
231 |
|
311 |
// Close the video file |
232 |
// Close the video file |
312 |
av_close_input_file(m_FormatCtx); |
233 |
avformat_close_input(&m_FormatCtx); |
313 |
m_opened=false; |
234 |
m_opened=false; |
314 |
} |
235 |
} |
315 |
} |
236 |
} |