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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
/* HBCore.h $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.fr/>.
It may be used under the terms of the GNU General Public License. */
#import <Foundation/Foundation.h>
@class HBJob;
@class HBPicture;
@class HBTitle;
@class HBStateFormatter;
NS_ASSUME_NONNULL_BEGIN
struct HBProgress
{
double percent;
int hours;
int minutes;
int seconds;
};
typedef struct HBProgress HBProgress;
// These constants specify the current state of HBCore.
typedef NS_ENUM(NSUInteger, HBState) {
HBStateIdle = 1, ///< HB is doing nothing
HBStateScanning = 2, ///< HB is scanning
HBStateScanDone = 4, ///< Scanning has been completed
HBStateWorking = 8, ///< HB is encoding
HBStatePaused = 16, ///< Encoding is paused
HBStateWorkDone = 32, ///< Encoding has been completed
HBStateMuxing = 64, ///< HB is muxing
HBStateSearching = 128 ///< HB is searching
};
// These constants specify the result of a scan or encode.
typedef NS_ENUM(NSUInteger, HBCoreResult) {
HBCoreResultDone,
HBCoreResultCanceled,
HBCoreResultFailed,
};
typedef void (^HBCoreProgressHandler)(HBState state, HBProgress progress, NSString *info);
typedef void (^HBCoreCompletionHandler)(HBCoreResult result);
/**
* HBCore is an Objective-C interface to the low-level HandBrake library.
* HBCore monitors state changes of libhb. It can also be used
* to implement properties that can be directly bound to elements of the gui.
*/
@interface HBCore : NSObject
/**
* Set the status of libdvdnav in low level HandBrake library.
* This should be called once before other functions HBCore are used.
*
* @param enabled whether libdvdnav is enabled or not.
*/
+ (void)setDVDNav:(BOOL)enabled;
/**
* Inits libhb globals.
*/
+ (void)initGlobal;
/**
* Performs the final cleanup for the process.
*/
+ (void)closeGlobal;
/**
* Registers a global error handler block.
*
* @param handler a block called with the error message.
*/
+ (void)registerErrorHandler:(void (^)(NSString *error))handler;
/**
* Opens low level HandBrake library. This should be called once before other
* functions HBCore are used.
*
* @param level the desired libhb logging level.
* @param queue the queue on which the callbacks will be called.
*/
- (instancetype)initWithLogLevel:(int)level queue:(dispatch_queue_t)queue NS_DESIGNATED_INITIALIZER;
/**
* Opens low level HandBrake library. This should be called once before other
* functions HBCore are used.
*
* @param level the desired libhb logging level
* @param name the instance debug name
*/
- (instancetype)initWithLogLevel:(int)level name:(NSString *)name;
/**
* Log level.
*/
@property (nonatomic, readwrite) int logLevel;
/**
* Set whether system sleep will be disable or not during a scan/encode
* Enabled by default.
*/
@property (nonatomic, readwrite) BOOL automaticallyPreventSleep;
/**
* Manually prevent system sleep if automaticallyPreventSleep is set to NO.
*/
- (void)preventSleep;
/**
* Manually allow system sleep if automaticallyPreventSleep is set to NO.
*/
- (void)allowSleep;
/**
* State formatter.
*/
@property (nonatomic, readwrite, strong) HBStateFormatter *stateFormatter;
/**
* Current state of HBCore.
*/
@property (nonatomic, readonly) HBState state;
/**
* The name of the core, used for debugging purpose.
*/
@property (nonatomic, copy) NSString *name;
/**
* Determines whether the scan operation can scan a particural URL or whether an additional decryption lib is needed.
*
* @param url the URL of the input file.
* @param error an error containing additional info.
*
* @return YES is the file at URL is scannable.
*/
- (BOOL)canScan:(NSURL *)url error:(NSError * __autoreleasing *)error;
/**
* Initiates an asynchronous scan operation and returns immediately.
*
* @param url the URL of the input file.
* @param index the index of the desired title. Use 0 to scan every title.
* @param previewsNum the number of previews image to generate.
* @param seconds the minimum duration of the wanted titles in seconds.
* @param progressHandler a block called periodically with the progress information.
* @param completionHandler a block called with the scan result.
*/
- (void)scanURL:(NSURL *)url titleIndex:(NSUInteger)index previews:(NSUInteger)previewsNum minDuration:(NSUInteger)seconds progressHandler:(HBCoreProgressHandler)progressHandler completionHandler:(HBCoreCompletionHandler)completionHandler;
/**
* Cancels the scan execution.
* Cancel can be invoked when the scan is running.
*/
- (void)cancelScan;
/**
* An array of HBTitles found by the latest scan.
*/
@property (nonatomic, readonly, copy) NSArray<HBTitle *> *titles;
/**
* This function converts an image created by libhb (specified via index)
* into an CGImage.
*
* @param index the index of the desired image.
* @param title Handle to hb_title_t of desired title
* @param frame a HBPicture instance that describe the image's frame.
* @param deinterlace whether the preview image must be deinterlaced or not.
*
* @return a CGImageRef of the wanted image, NULL if the index is out of bounds.
*/
- (nullable CGImageRef)copyImageAtIndex:(NSUInteger)index
forTitle:(HBTitle *)title
pictureFrame:(HBPicture *)frame
deinterlace:(BOOL)deinterlace
rotate:(int)angle
flipped:(BOOL)flipped CF_RETURNS_RETAINED;
/**
* Returns the counts of the available previews images.
*/
- (NSUInteger)imagesCountForTitle:(HBTitle *)title;
/**
* Initiates an asynchronous encode operation and returns immediately.
*
* @param job the job to encode
* @param progressHandler a block called periodically with the progress information.
* @param completionHandler a block called with the scan result
*/
- (void)encodeJob:(HBJob *)job progressHandler:(HBCoreProgressHandler)progressHandler completionHandler:(HBCoreCompletionHandler)completionHandler;
/**
* Stops encode operation and releases resources.
* Cancel can be invoked when the encode is running.
*/
- (void)cancelEncode;
/**
* Pauses the encode operation.
* Pause can be invoked when the encode is running.
*/
- (void)pause;
/**
* Resumes a paused encoding session.
* Resume can be invoked when the encode is running.
*/
- (void)resume;
@end
NS_ASSUME_NONNULL_END
|