-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathAVPacketObject.m
71 lines (62 loc) · 1.2 KB
/
AVPacketObject.m
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
//
// AVPacketObject.m
// FFmpegPlayTest
//
// Created by Jack on 11/13/12.
// Copyright (c) 2012 Jack. All rights reserved.
//
#import "AVPacketObject.h"
@interface AVPacketObject ()
{
AVPacket* _avPacket;
}
@end
@implementation AVPacketObject
#pragma mark Class Construction
- (id) init
{
self = [super init];
if (self)
{
_avPacket = nil;
}
return self;
}
- (id) initWithAVPacketNoCopy: (AVPacket*) packet
{
self = [super init];
if (self)
{
_avPacket = packet;
// the hack, to make packet allocate correctly
if (av_dup_packet(_avPacket) < 0) {
return nil;
}
}
return self;
}
- (id) initWithAVPacket:(AVPacket *)packet
{
self = [super init];
if (self) {
_avPacket = (AVPacket*) av_malloc(sizeof(AVPacket));
av_init_packet(_avPacket);
if (av_copy_packet(_avPacket, packet) < 0){
free(_avPacket);
return nil;
}
}
return self;
}
- (void)dealloc
{
if (_avPacket) {
// Free packet held data
av_free_packet(_avPacket);
// Free packet itself
av_free(_avPacket);
_avPacket = nil;
}
[super dealloc];
}
@end