-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathCCIMovie.cpp
96 lines (80 loc) · 2.36 KB
/
CCIMovie.cpp
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
//
// CCIMovie.cpp
// CocosInterpreterTest
//
// Created by Wu Tong on 13-4-8.
//
//
#include "CCIMovie.h"
#include "CCFileUtils.h"
#include "CCIBufferReader.h"
#include "CCIFrameLabel.h"
NS_CC_EXT_BEGIN
static CCDictionary * movies = NULL;
CCIMovie * CCIMovie::decodeFromFile(std::string filename){
if (!movies) {
movies = new CCDictionary();
}
CCIMovie * movie = (CCIMovie *)movies->objectForKey(filename);
if (movie) {
return movie;
}
const char * fullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(filename.c_str());
int fileSize = 0;
unsigned char * swfdata = CCFileUtils::sharedFileUtils()->getFileData(fullPath, "rb", (unsigned long *)(&fileSize));
if (fileSize < 0)
{
delete[] swfdata;
return NULL;
}
CCIBufferReader bufferReader;
bufferReader.setData(swfdata, fileSize);
delete[] swfdata;
movie = new CCIMovie();
movie->frameLabels = CCDictionary::create();
movie->frameLabels->retain();
movie->header = CCIMovieHeader::create(&bufferReader);
bufferReader.version = movie->header->getVersion();
if (movie->header->getVersion()>=8) {
movie->fileAttributes = (CCIFileAttributes *)CCIMovieTag::next(&bufferReader);
}
CCIMovieTag * tag = CCIMovieTag::next(&bufferReader);
int tagIndex = 0;
while (tag) {
movie->tags.push_back(tag);
tag = CCIMovieTag::next(&bufferReader);
tagIndex++;
if (tag&&tag->getTagType()==TagTypeFrameLabel) {
CCIFrameLabel * frameLbl = (CCIFrameLabel *)tag;
movie->frameLabels->setObject(CCString::createWithFormat("%d",tagIndex), frameLbl->getName());
}
}
bufferReader.clear();
movies->setObject(movie,filename);
movie->release();
return movie;
}
std::vector<CCIMovieTag *> CCIMovie::getTags(){
return this->tags;
}
CCIMovieHeader * CCIMovie::getHeader(){
return this->header;
}
CCDictionary * CCIMovie::getFrameLabels(){
return this->frameLabels;
}
void CCIMovie::cleanup(){
movies->release();
movies = NULL;
}
CCIMovie::~CCIMovie(){
for (int i=0; i<tags.size(); i++) {
CCIMovieTag * tag = tags[i];
delete tag;
}
tags.clear();
delete header;
delete fileAttributes;
this->frameLabels->release();
}
NS_CC_EXT_END