This repository has been archived by the owner on Jul 30, 2022. It is now read-only.
mirrored from https://chromium.googlesource.com/webm/webmquicktime
-
Notifications
You must be signed in to change notification settings - Fork 10
/
WebMExportGuiVideo.c
200 lines (147 loc) · 6.07 KB
/
WebMExportGuiVideo.c
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// Copyright (c) 2010 The WebM project authors. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
#include "WebMExportStructs.h"
#if defined(__APPLE_CC__)
#include <QuickTime/QuickTime.h>
#else
#include <QuickTimeComponents.h>
#endif
#include "log.h"
#include "WebMExportVersions.h"
#include "WebMExportGuiVideo.h"
ComponentResult getDefaultVP8Atom(WebMExportGlobalsPtr globals)
{
ComponentResult err = noErr;
dbg_printf("[WebM - %08lx] getDefaultVP8Atom()\n", (UInt32) globals);
ComponentInstance stdVideo = NULL;
err = OpenADefaultComponent(StandardCompressionType, StandardCompressionSubType, &stdVideo);
dbg_printf("[WebM] getDefaultVP8Atom()\n", (UInt32) globals);
long sc_prefs = scAllowZeroFrameRate | scAllowZeroKeyFrameRate | scShowDataRateAsKilobits;
err = SCSetInfo(stdVideo, scPreferenceFlagsType, &sc_prefs);
if (err) goto bail;
SCSpatialSettings ss = {kVP8CodecFormatType, (CodecComponent) kVP8CodecFormatType,
0, codecNormalQuality
};
SCTemporalSettings ts = {codecNormalQuality, 0, 64};
ts.frameRate = FloatToFixed(globals->framerate);
SCDataRateSettings ds = {0, 0, 0, 0};
err = SCSetInfo(stdVideo, scSpatialSettingsType, &ss);
if (err) goto bail;
err = SCSetInfo(stdVideo, scTemporalSettingsType, &ts);
if (err) goto bail;
err = SCSetInfo(stdVideo, scDataRateSettingsType, &ds);
if (err) goto bail;
bail:
dbg_printf("----------- %08lx\n" , (UInt32)stdVideo);
if (stdVideo != NULL)
{
//here we try to get settings even if there was an error earlier
err = SCGetSettingsAsAtomContainer(stdVideo, &globals->videoSettingsAtom);
dbg_dumpAtom(globals->videoSettingsAtom);
CloseComponent(stdVideo);
}
return err;
}
//TODO don't think WindowRef is needed or used.
ComponentResult OpenVP8Dlg(WebMExportGlobalsPtr globals, WindowRef window)
{
ComponentResult err = noErr;
ComponentInstance stdVideo = NULL;
PicHandle currentPictureHandle = NULL;
// SCExtendedProcs xProcs;
dbg_printf("[WebM] >> [%08lx] :: OpenVP8Dlg()\n", (UInt32) globals);
if (globals->videoSettingsAtom == NULL)
getDefaultVP8Atom(globals);
err = OpenADefaultComponent(StandardCompressionType, StandardCompressionSubType, &stdVideo);
if (err) goto bail;
err = SCSetSettingsFromAtomContainer(stdVideo, globals->videoSettingsAtom);
if (err) goto bail;
Handle compressionList = NULL;
compressionList = NewHandleClear(sizeof(OSType));
HLock(compressionList);
*(OSType *)*compressionList = kVP8CodecFormatType;
err = SCSetInfo(stdVideo, scCompressionListType, &compressionList);
if (err)
{
dbg_printf("[WebM] Couldn't set vp8 to only codec in list err = %d\n", err);
goto bail;
}
OSType manufacturer = kGoogManufacturer;
err = SCSetInfo(stdVideo, scCodecManufacturerType, &manufacturer);
if (err)
{
dbg_printf("[WebM] Couldn't set scCodecManufacturerType err = %d\n", err);
goto bail;
}
//Set the image to show in the test box
TimeScale movieTime = GetMovieTime(globals->setdlg_movie, NULL);
if (movieTime == 0)
movieTime = GetMoviePosterTime(globals->setdlg_movie);
err = GetMoviesError();
dbg_printf("[Webm] Set picture to time %ld\n", movieTime);
//This chunk of code is responsible for adding a video preview to the vp8
//options dialog. Currently it is causing crashes. After much debugging,
//I've determined that one of quicktimes function corrupts memory in the heap
//when using this option. Perhaps if the encoder use changes then this
//can be uncommented to allow the preview. See
//http://code.google.com/p/webm/issues/detail?id=272
/*if (!err)
{
currentPictureHandle = GetMoviePict(globals->setdlg_movie, movieTime);
dbg_printf("[Webm] GetMoviePict < %ld\n", currentPictureHandle);
if (currentPictureHandle != NULL)
{
Rect rect;
QDGetPictureBounds(currentPictureHandle, &rect);
dbg_printf("[WebM] QDGetPictureBounds %d %d %d %d\n",
rect.top, rect.left, rect.bottom, rect.right);
short testFlags = scPreferScalingAndCropping
| scDontDetermineSettingsFromTestImage;
err = SCSetTestImagePictHandle(stdVideo,
currentPictureHandle, &rect, testFlags);
dbg_printf("[WebM] SCSetTestImagePictHandle %d\n", err);
}
}*/
//this does the user dialog and waits until they exit
err = SCRequestSequenceSettings(stdVideo);
if (err) goto bail;
err = SCGetSettingsAsAtomContainer(stdVideo, &globals->videoSettingsAtom);
if (globals->videoSettingsCustom == NULL)
{
globals->videoSettingsCustom = NewHandleClear(0);
SetHandleSize(globals->videoSettingsCustom, 0);
}
err = SCGetInfo(stdVideo, scCodecSettingsType, &globals->videoSettingsCustom);
if (err) goto bail;
bail:
if (stdVideo != NULL)
CloseComponent(stdVideo);
if (currentPictureHandle != NULL)
DisposeHandle((Handle)currentPictureHandle);
if (compressionList != NULL)
DisposeHandle(compressionList);
return err;
}
ComponentResult getVideoComponentInstace(WebMExportGlobalsPtr glob, ComponentInstance *videoCI)
{
ComponentResult err =noErr;
OpenADefaultComponent(StandardCompressionType, StandardCompressionSubType, videoCI);
if (err) goto bail;
if (glob->videoSettingsAtom == NULL)
{
getDefaultVP8Atom(glob);
}
err = SCSetSettingsFromAtomContainer(*videoCI, glob->videoSettingsAtom);
if (err) goto bail;
if (glob->videoSettingsCustom != NULL)
{
err = SCSetInfo(*videoCI, scCodecSettingsType, &glob->videoSettingsCustom);
}
bail:
return err;
}