-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathreadme.txt
More file actions
80 lines (56 loc) · 2.28 KB
/
readme.txt
File metadata and controls
80 lines (56 loc) · 2.28 KB
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
this is just a sample of audio queue used with ffmpeg audio decoding
it is for education only and is not in anyway complete.
You will also need the following code in the streamer class (your equivalent of frames)
- (NSInteger)decode {
if (_inBuffer) return _decodedDataSize;
_decodedDataSize = 0;
AVPacket *packet = [self readPacket];
NSLog(@"read packet");
while (packet && packet->size > 0) {
NSLog(@"decoding packet");
if (_audioBufferSize < FFMAX(packet->size * sizeof(*_audioBuffer), AVCODEC_MAX_AUDIO_FRAME_SIZE)) {
_audioBufferSize = FFMAX(packet->size * sizeof(*_audioBuffer), AVCODEC_MAX_AUDIO_FRAME_SIZE);
av_free(_audioBuffer);
_audioBuffer = av_malloc(_audioBufferSize);
}
_decodedDataSize = _audioBufferSize;
NSInteger len = avcodec_decode_audio3(_audioCodecContext, _audioBuffer, &_decodedDataSize, packet);
NSLog(@"packet size %d ",packet->size);
if (len < 0) {
NSLog(@"Could not decode audio packet.");
return 0;
}
packet->data += len;
packet->size -= len;
if (_decodedDataSize <= 0) {
NSLog(@"Decoding was completed.");
packet = NULL;
break;
}
_inBuffer = YES;
}
NSLog(@"added decoded packet...decoded %d ",_decodedDataSize);
return _decodedDataSize;
}
- (void)nextPacket {
_inBuffer = NO;
}
- (AVPacket*)readPacket {
if (_currentPacket.size > 0 || _inBuffer) return &_currentPacket;
NSMutableData *packetData = [audioPacketQueue objectAtIndex:0];
_packet = [packetData mutableBytes];
NSLog(@"got audio stream");
if (_packet->dts != AV_NOPTS_VALUE) {
_packet->dts += av_rescale_q(0, AV_TIME_BASE_Q, _audioStream->time_base);
}
if (_packet->pts != AV_NOPTS_VALUE) {
_packet->pts += av_rescale_q(0, AV_TIME_BASE_Q, _audioStream->time_base);
}
NSLog(@"ready with audio");
[audioPacketQueueLock lock];
audioPacketQueueSize -= _packet->size;
[audioPacketQueue removeObjectAtIndex:0];
[audioPacketQueueLock unlock];
_currentPacket = *(_packet);
return &_currentPacket;
}