Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f589789

Browse files
committed
FFTPlayer0x33 use double packet queue, double decoder thread
1 parent 30d902a commit f589789

File tree

1 file changed

+44
-17
lines changed

1 file changed

+44
-17
lines changed

‎FFmpegTutorial/t33/FFTPlayer0x33.m‎

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ @interface FFTPlayer0x33 ()<FFTDecoderDelegate>
4141
//音频重采样
4242
FFTAudioResample *_audioResample;
4343

44-
FFTPacketQueue *_packetQueue;
44+
FFTPacketQueue *_audioPacketQueue;
45+
FFTPacketQueue *_videoPacketQueue;
4546

4647
FFTVideoFrameQueue *_videoFrameQueue;
4748
FFTAudioFrameQueue *_audioFrameQueue;
@@ -62,7 +63,8 @@ @interface FFTPlayer0x33 ()<FFTDecoderDelegate>
6263

6364
//读包线程
6465
@property (nonatomic, strong) FFTThread *readThread;
65-
@property (nonatomic, strong) FFTThread *decoderThread;
66+
@property (nonatomic, strong) FFTThread *audioDecoderThread;
67+
@property (nonatomic, strong) FFTThread *videoDecoderThread;
6668
@property (nonatomic, strong) FFTThread *videoThread;
6769

6870
@property (atomic, assign) int abort_request;
@@ -85,7 +87,8 @@ static int decode_interrupt_cb(void *ctx)
8587
- (void)_stop
8688
{
8789
self.abort_request = 1;
88-
[_packetQueue cancel];
90+
[_audioPacketQueue cancel];
91+
[_videoPacketQueue cancel];
8992
[_videoFrameQueue cancel];
9093
[_audioFrameQueue cancel];
9194

@@ -100,9 +103,14 @@ - (void)_stop
100103
[self.readThread join];
101104
}
102105

103-
if (self.decoderThread) {
104-
[self.decoderThread cancel];
105-
[self.decoderThread join];
106+
if (self.audioDecoderThread) {
107+
[self.audioDecoderThread cancel];
108+
[self.audioDecoderThread join];
109+
}
110+
111+
if (self.videoDecoderThread) {
112+
[self.videoDecoderThread cancel];
113+
[self.videoDecoderThread join];
106114
}
107115

108116
if (self.videoThread) {
@@ -132,13 +140,17 @@ - (void)prepareToPlay
132140
NSAssert(NO, @"不允许重复创建");
133141
}
134142

135-
_packetQueue = [[FFTPacketQueue alloc] init];
143+
_audioPacketQueue = [[FFTPacketQueue alloc] init];
144+
_videoPacketQueue = [[FFTPacketQueue alloc] init];
136145

137146
self.readThread = [[FFTThread alloc] initWithTarget:self selector:@selector(readPacketsFunc) object:nil];
138147
self.readThread.name = @"mr-read";
139148

140-
self.decoderThread = [[FFTThread alloc] initWithTarget:self selector:@selector(decoderFunc) object:nil];
141-
self.decoderThread.name = @"mr-decoder";
149+
self.audioDecoderThread = [[FFTThread alloc] initWithTarget:self selector:@selector(audioDecoderFunc) object:nil];
150+
self.audioDecoderThread.name = @"audio-decoder";
151+
152+
self.videoDecoderThread = [[FFTThread alloc] initWithTarget:self selector:@selector(videoDecoderFunc) object:nil];
153+
self.videoDecoderThread.name = @"video-decoder";
142154

143155
self.videoThread = [[FFTThread alloc] initWithTarget:self selector:@selector(videoThreadFunc) object:nil];
144156
self.videoThread.name = @"mr-v-display";
@@ -171,9 +183,9 @@ - (void)readPacketLoop:(AVFormatContext *)formatCtx
171183
pkt->data = NULL;
172184
pkt->size = 0;
173185
pkt->stream_index = _videoDecoder.streamIdx;
174-
[_packetQueue enQueue:pkt];
186+
[_videoPacketQueue enQueue:pkt];
175187
pkt->stream_index = _audioDecoder.streamIdx;
176-
[_packetQueue enQueue:pkt];
188+
[_audioPacketQueue enQueue:pkt];
177189
break;
178190
}
179191

@@ -192,15 +204,15 @@ - (void)readPacketLoop:(AVFormatContext *)formatCtx
192204
if (pkt->data != NULL) {
193205
self.videoPktCount++;
194206
}
195-
[_packetQueue enQueue:pkt];
207+
[_videoPacketQueue enQueue:pkt];
196208
}
197209
break;
198210
case AVMEDIA_TYPE_AUDIO:
199211
{
200212
if (pkt->data != NULL) {
201213
self.audioPktCount++;
202214
}
203-
[_packetQueue enQueue:pkt];
215+
[_audioPacketQueue enQueue:pkt];
204216
}
205217
break;
206218
default:
@@ -365,8 +377,9 @@ - (void)readPacketsFunc
365377
});
366378

367379
_formatCtx = formatCtx;
368-
[self.decoderThread start];
369-
//[self.videoThread start];
380+
[self.audioDecoderThread start];
381+
[self.videoDecoderThread start];
382+
370383
//循环读包
371384
[self readPacketLoop:formatCtx];
372385
}
@@ -481,11 +494,24 @@ - (void)decodePkt:(AVPacket *)pkt
481494
}
482495
}
483496

484-
- (void)decoderFunc
497+
- (void)audioDecoderFunc
498+
{
499+
while (!self.abort_request) {
500+
__weakSelf__
501+
[_audioPacketQueue deQueue:^(AVPacket * pkt) {
502+
__strongSelf__
503+
if (pkt) {
504+
[self decodePkt:pkt];
505+
}
506+
}];
507+
}
508+
}
509+
510+
- (void)videoDecoderFunc
485511
{
486512
while (!self.abort_request) {
487513
__weakSelf__
488-
[_packetQueue deQueue:^(AVPacket * pkt) {
514+
[_videoPacketQueue deQueue:^(AVPacket * pkt) {
489515
__strongSelf__
490516
if (pkt) {
491517
[self decodePkt:pkt];
@@ -494,6 +520,7 @@ - (void)decoderFunc
494520
}
495521
}
496522

523+
497524
#pragma mark - FFTDecoderDelegate
498525

499526
- (void)decoder:(FFTDecoder *)decoder reveivedAFrame:(AVFrame *)aFrame

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /