OLD | NEW |
1 // Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 1 // Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
2 // | 2 // |
3 // Use of this source code is governed by a BSD-style license | 3 // Use of this source code is governed by a BSD-style license |
4 // that can be found in the LICENSE file in the root of the source | 4 // that can be found in the LICENSE file in the root of the source |
5 // tree. An additional intellectual property rights grant can be found | 5 // tree. An additional intellectual property rights grant can be found |
6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
8 | 8 |
9 | 9 |
10 #include "EbmlBufferWriter.h" | 10 #include "EbmlBufferWriter.h" |
11 #include "EbmlIDs.h" | 11 #include "EbmlIDs.h" |
12 #include "WebMElement.h" | 12 #include "WebMElement.h" |
13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 #include "vpx/vpx_integer.h" |
14 | 15 |
15 #define kVorbisPrivateMaxSize 4000 | 16 #define kVorbisPrivateMaxSize 4000 |
16 | 17 |
17 void writeHeader(EbmlGlobal *glob) { | 18 void writeHeader(EbmlGlobal *glob) { |
18 EbmlLoc start; | 19 EbmlLoc start; |
19 Ebml_StartSubElement(glob, &start, EBML); | 20 Ebml_StartSubElement(glob, &start, EBML); |
20 Ebml_SerializeUnsigned(glob, EBMLVersion, 1); | 21 Ebml_SerializeUnsigned(glob, EBMLVersion, 1); |
21 Ebml_SerializeUnsigned(glob, EBMLReadVersion, 1); // EBML Read Version | 22 Ebml_SerializeUnsigned(glob, EBMLReadVersion, 1); // EBML Read Version |
22 Ebml_SerializeUnsigned(glob, EBMLMaxIDLength, 4); // EBML Max ID Length | 23 Ebml_SerializeUnsigned(glob, EBMLMaxIDLength, 4); // EBML Max ID Length |
23 Ebml_SerializeUnsigned(glob, EBMLMaxSizeLength, 8); // EBML Max Size Length | 24 Ebml_SerializeUnsigned(glob, EBMLMaxSizeLength, 8); // EBML Max Size Length |
(...skipping 12 matching lines...) Expand all Loading... |
36 Ebml_Serialize(glob, &blockLength, sizeof(blockLength), 4); | 37 Ebml_Serialize(glob, &blockLength, sizeof(blockLength), 4); |
37 trackNumber |= 0x80; // TODO check track nubmer < 128 | 38 trackNumber |= 0x80; // TODO check track nubmer < 128 |
38 Ebml_Write(glob, &trackNumber, 1); | 39 Ebml_Write(glob, &trackNumber, 1); |
39 // Ebml_WriteSigned16(glob, timeCode,2); //this is 3 bytes | 40 // Ebml_WriteSigned16(glob, timeCode,2); //this is 3 bytes |
40 Ebml_Serialize(glob, &timeCode, sizeof(timeCode), 2); | 41 Ebml_Serialize(glob, &timeCode, sizeof(timeCode), 2); |
41 unsigned char flags = 0x00 | (isKeyframe ? 0x80 : 0x00) | (lacingFlag << 1) |
discardable; | 42 unsigned char flags = 0x00 | (isKeyframe ? 0x80 : 0x00) | (lacingFlag << 1) |
discardable; |
42 Ebml_Write(glob, &flags, 1); | 43 Ebml_Write(glob, &flags, 1); |
43 Ebml_Write(glob, data, dataLength); | 44 Ebml_Write(glob, data, dataLength); |
44 } | 45 } |
45 | 46 |
46 static UInt64 generateTrackID(unsigned int trackNumber) { | 47 static uint64_t generateTrackID(unsigned int trackNumber) { |
47 UInt64 t = time(NULL) * trackNumber; | 48 uint64_t t = time(NULL) * trackNumber; |
48 UInt64 r = rand(); | 49 uint64_t r = rand(); |
49 r = r << 32; | 50 r = r << 32; |
50 r += rand(); | 51 r += rand(); |
51 UInt64 rval = t ^ r; | 52 uint64_t rval = t ^ r; |
52 return rval; | 53 return rval; |
53 } | 54 } |
54 | 55 |
55 void writeVideoTrack(EbmlGlobal *glob, unsigned int trackNumber, int flagLacing, | 56 void writeVideoTrack(EbmlGlobal *glob, unsigned int trackNumber, |
56 char *codecId, unsigned int pixelWidth, unsigned int pixelH
eight, | 57 int flagLacing, const char *codecId, |
| 58 unsigned int pixelWidth, unsigned int pixelHeight, |
57 double frameRate) { | 59 double frameRate) { |
58 EbmlLoc start; | 60 EbmlLoc start; |
59 Ebml_StartSubElement(glob, &start, TrackEntry); | 61 Ebml_StartSubElement(glob, &start, TrackEntry); |
60 Ebml_SerializeUnsigned(glob, TrackNumber, trackNumber); | 62 Ebml_SerializeUnsigned(glob, TrackNumber, trackNumber); |
61 UInt64 trackID = generateTrackID(trackNumber); | 63 uint64_t trackID = generateTrackID(trackNumber); |
62 Ebml_SerializeUnsigned(glob, TrackUID, trackID); | 64 Ebml_SerializeUnsigned(glob, TrackUID, trackID); |
63 Ebml_SerializeString(glob, CodecName, "VP8"); // TODO shouldn't be fixed | 65 Ebml_SerializeString(glob, CodecName, "VP8"); // TODO shouldn't be fixed |
64 | 66 |
65 Ebml_SerializeUnsigned(glob, TrackType, 1); // video is always 1 | 67 Ebml_SerializeUnsigned(glob, TrackType, 1); // video is always 1 |
66 Ebml_SerializeString(glob, CodecID, codecId); | 68 Ebml_SerializeString(glob, CodecID, codecId); |
67 { | 69 { |
68 EbmlLoc videoStart; | 70 EbmlLoc videoStart; |
69 Ebml_StartSubElement(glob, &videoStart, Video); | 71 Ebml_StartSubElement(glob, &videoStart, Video); |
70 Ebml_SerializeUnsigned(glob, PixelWidth, pixelWidth); | 72 Ebml_SerializeUnsigned(glob, PixelWidth, pixelWidth); |
71 Ebml_SerializeUnsigned(glob, PixelHeight, pixelHeight); | 73 Ebml_SerializeUnsigned(glob, PixelHeight, pixelHeight); |
72 Ebml_SerializeFloat(glob, FrameRate, frameRate); | 74 Ebml_SerializeFloat(glob, FrameRate, frameRate); |
73 Ebml_EndSubElement(glob, &videoStart); // Video | 75 Ebml_EndSubElement(glob, &videoStart); // Video |
74 } | 76 } |
75 Ebml_EndSubElement(glob, &start); // Track Entry | 77 Ebml_EndSubElement(glob, &start); // Track Entry |
76 } | 78 } |
77 void writeAudioTrack(EbmlGlobal *glob, unsigned int trackNumber, int flagLacing, | 79 void writeAudioTrack(EbmlGlobal *glob, unsigned int trackNumber, |
78 char *codecId, double samplingFrequency, unsigned int chann
els, | 80 int flagLacing, const char *codecId, |
| 81 double samplingFrequency, unsigned int channels, |
79 unsigned char *private, unsigned long privateSize) { | 82 unsigned char *private, unsigned long privateSize) { |
80 EbmlLoc start; | 83 EbmlLoc start; |
81 Ebml_StartSubElement(glob, &start, TrackEntry); | 84 Ebml_StartSubElement(glob, &start, TrackEntry); |
82 Ebml_SerializeUnsigned(glob, TrackNumber, trackNumber); | 85 Ebml_SerializeUnsigned(glob, TrackNumber, trackNumber); |
83 UInt64 trackID = generateTrackID(trackNumber); | 86 uint64_t trackID = generateTrackID(trackNumber); |
84 Ebml_SerializeUnsigned(glob, TrackUID, trackID); | 87 Ebml_SerializeUnsigned(glob, TrackUID, trackID); |
85 Ebml_SerializeUnsigned(glob, TrackType, 2); // audio is always 2 | 88 Ebml_SerializeUnsigned(glob, TrackType, 2); // audio is always 2 |
86 // I am using defaults for thesed required fields | 89 // I am using defaults for thesed required fields |
87 /* Ebml_SerializeUnsigned(glob, FlagEnabled, 1); | 90 /* Ebml_SerializeUnsigned(glob, FlagEnabled, 1); |
88 Ebml_SerializeUnsigned(glob, FlagDefault, 1); | 91 Ebml_SerializeUnsigned(glob, FlagDefault, 1); |
89 Ebml_SerializeUnsigned(glob, FlagForced, 1); | 92 Ebml_SerializeUnsigned(glob, FlagForced, 1); |
90 Ebml_SerializeUnsigned(glob, FlagLacing, flagLacing);*/ | 93 Ebml_SerializeUnsigned(glob, FlagLacing, flagLacing);*/ |
91 Ebml_SerializeString(glob, CodecID, codecId); | 94 Ebml_SerializeString(glob, CodecID, codecId); |
92 Ebml_SerializeData(glob, CodecPrivate, private, privateSize); | 95 Ebml_SerializeData(glob, CodecPrivate, private, privateSize); |
93 | 96 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 { | 208 { |
206 Ebml_StartSubElement(ebml_out, ebmlLoc, 0xA3); | 209 Ebml_StartSubElement(ebml_out, ebmlLoc, 0xA3); |
207 Ebml_Write1UInt(ebml_out, block.TrackNumber); | 210 Ebml_Write1UInt(ebml_out, block.TrackNumber); |
208 Ebml_WriteSigned16(ebml_out,block.TimeCode); | 211 Ebml_WriteSigned16(ebml_out,block.TimeCode); |
209 unsigned char flags = 0x00 | (block.iskey ? 0x80:0x00) | (block.lacing << 1)
| block.discardable; | 212 unsigned char flags = 0x00 | (block.iskey ? 0x80:0x00) | (block.lacing << 1)
| block.discardable; |
210 Ebml_Write1UInt(ebml_out, flags); // TODO this may be the wrong function | 213 Ebml_Write1UInt(ebml_out, flags); // TODO this may be the wrong function |
211 Ebml_Serialize(ebml_out, block.data, block.dataLength); | 214 Ebml_Serialize(ebml_out, block.data, block.dataLength); |
212 Ebml_EndSubElement(ebml_out,ebmlLoc); | 215 Ebml_EndSubElement(ebml_out,ebmlLoc); |
213 } | 216 } |
214 */ | 217 */ |
OLD | NEW |