Skip to content

Commit e8ca1c7

Browse files
DichenZhang1Gerrit Code Review
authored andcommitted
Merge "HeifWriter / AvifWriter: fix Java doc" into androidx-main
2 parents 69e5970 + 9e53b09 commit e8ca1c7

File tree

3 files changed

+219
-7
lines changed

3 files changed

+219
-7
lines changed

heifwriter/heifwriter/src/main/java/androidx/heifwriter/AvifWriter.java

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,112 @@ private Builder(String path, FileDescriptor fd,
291291
}
292292
}
293293

294+
/**
295+
* Start the avif writer. Can only be called once.
296+
*
297+
* @throws IllegalStateException if called more than once.
298+
*/
299+
@Override
300+
public void start() {
301+
super.start();
302+
}
303+
304+
/**
305+
* Add one YUV buffer to the avif file.
306+
*
307+
* @param format The YUV format as defined in {@link android.graphics.ImageFormat}, currently
308+
* only support YUV_420_888.
309+
*
310+
* @param data byte array containing the YUV data. If the format has more than one planes,
311+
* they must be concatenated.
312+
*
313+
* @throws IllegalStateException if not started or not configured to use buffer input.
314+
*/
315+
@Override
316+
public void addYuvBuffer(int format, @NonNull byte[] data) {
317+
super.addYuvBuffer(format, data);
318+
}
319+
320+
/**
321+
* Retrieves the input surface for encoding.
322+
*
323+
* @return the input surface if configured to use surface input.
324+
*
325+
* @throws IllegalStateException if called after start or not configured to use surface input.
326+
*/
327+
@Override
328+
public @NonNull Surface getInputSurface() {
329+
return super.getInputSurface();
330+
}
331+
332+
/**
333+
* Set the timestamp (in nano seconds) of the last input frame to encode.
334+
*
335+
* This call is only valid for surface input. Client can use this to stop the avif writer
336+
* earlier before the maximum number of images are written. If not called, the writer will
337+
* only stop when the maximum number of images are written.
338+
*
339+
* @param timestampNs timestamp (in nano seconds) of the last frame that will be written to the
340+
* avif file. Frames with timestamps larger than the specified value will not
341+
* be written. However, if a frame already started encoding when this is set,
342+
* all tiles within that frame will be encoded.
343+
*
344+
* @throws IllegalStateException if not started or not configured to use surface input.
345+
*/
346+
@Override
347+
public void setInputEndOfStreamTimestamp(@IntRange(from = 0) long timestampNs) {
348+
super.setInputEndOfStreamTimestamp(timestampNs);
349+
}
350+
351+
/**
352+
* Add one bitmap to the avif file.
353+
*
354+
* @param bitmap the bitmap to be added to the file.
355+
* @throws IllegalStateException if not started or not configured to use bitmap input.
356+
*/
357+
@Override
358+
public void addBitmap(@NonNull Bitmap bitmap) {
359+
super.addBitmap(bitmap);
360+
}
361+
362+
/**
363+
* Add Exif data for the specified image. The data must be a valid Exif data block,
364+
* starting with "Exif\0\0" followed by the TIFF header (See JEITA CP-3451C Section 4.5.2.)
365+
*
366+
* @param imageIndex index of the image, must be a valid index for the max number of image
367+
* specified by {@link Builder#setMaxImages(int)}.
368+
* @param exifData byte buffer containing a Exif data block.
369+
* @param offset offset of the Exif data block within exifData.
370+
* @param length length of the Exif data block.
371+
*/
372+
@Override
373+
public void addExifData(int imageIndex, @NonNull byte[] exifData, int offset, int length) {
374+
super.addExifData(imageIndex, exifData, offset, length);
375+
}
376+
377+
/**
378+
* Stop the avif writer synchronously. Throws exception if the writer didn't finish writing
379+
* successfully. Upon a success return:
380+
*
381+
* - For buffer and bitmap inputs, all images sent before stop will be written.
382+
*
383+
* - For surface input, images with timestamp on or before that specified in
384+
* {@link #setInputEndOfStreamTimestamp(long)} will be written. In case where
385+
* {@link #setInputEndOfStreamTimestamp(long)} was never called, stop will block
386+
* until maximum number of images are received.
387+
*
388+
* @param timeoutMs Maximum time (in microsec) to wait for the writer to complete, with zero
389+
* indicating waiting indefinitely.
390+
* @see #setInputEndOfStreamTimestamp(long)
391+
* @throws Exception if encountered error, in which case the output file may not be valid. In
392+
* particular, {@link TimeoutException} is thrown when timed out, and {@link
393+
* MediaCodec.CodecException} is thrown when encountered codec error.
394+
*/
395+
@Override
396+
public void stop(@IntRange(from = 0) long timeoutMs) throws Exception {
397+
super.stop(timeoutMs);
398+
}
399+
294400
@SuppressLint("WrongConstant")
295401
@SuppressWarnings("WeakerAccess") /* synthetic access */
296402
AvifWriter(@NonNull String path,

heifwriter/heifwriter/src/main/java/androidx/heifwriter/HeifWriter.java

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,112 @@ private Builder(String path, FileDescriptor fd,
276276
}
277277
}
278278

279+
/**
280+
* Start the heif writer. Can only be called once.
281+
*
282+
* @throws IllegalStateException if called more than once.
283+
*/
284+
@Override
285+
public void start() {
286+
super.start();
287+
}
288+
289+
/**
290+
* Add one YUV buffer to the heif file.
291+
*
292+
* @param format The YUV format as defined in {@link android.graphics.ImageFormat}, currently
293+
* only support YUV_420_888.
294+
*
295+
* @param data byte array containing the YUV data. If the format has more than one planes,
296+
* they must be concatenated.
297+
*
298+
* @throws IllegalStateException if not started or not configured to use buffer input.
299+
*/
300+
@Override
301+
public void addYuvBuffer(int format, @NonNull byte[] data) {
302+
super.addYuvBuffer(format, data);
303+
}
304+
305+
/**
306+
* Retrieves the input surface for encoding.
307+
*
308+
* @return the input surface if configured to use surface input.
309+
*
310+
* @throws IllegalStateException if called after start or not configured to use surface input.
311+
*/
312+
@Override
313+
public @NonNull Surface getInputSurface() {
314+
return super.getInputSurface();
315+
}
316+
317+
/**
318+
* Set the timestamp (in nano seconds) of the last input frame to encode.
319+
*
320+
* This call is only valid for surface input. Client can use this to stop the heif writer
321+
* earlier before the maximum number of images are written. If not called, the writer will
322+
* only stop when the maximum number of images are written.
323+
*
324+
* @param timestampNs timestamp (in nano seconds) of the last frame that will be written to the
325+
* heif file. Frames with timestamps larger than the specified value will not
326+
* be written. However, if a frame already started encoding when this is set,
327+
* all tiles within that frame will be encoded.
328+
*
329+
* @throws IllegalStateException if not started or not configured to use surface input.
330+
*/
331+
@Override
332+
public void setInputEndOfStreamTimestamp(@IntRange(from = 0) long timestampNs) {
333+
super.setInputEndOfStreamTimestamp(timestampNs);
334+
}
335+
336+
/**
337+
* Add one bitmap to the heif file.
338+
*
339+
* @param bitmap the bitmap to be added to the file.
340+
* @throws IllegalStateException if not started or not configured to use bitmap input.
341+
*/
342+
@Override
343+
public void addBitmap(@NonNull Bitmap bitmap) {
344+
super.addBitmap(bitmap);
345+
}
346+
347+
/**
348+
* Add Exif data for the specified image. The data must be a valid Exif data block,
349+
* starting with "Exif\0\0" followed by the TIFF header (See JEITA CP-3451C Section 4.5.2.)
350+
*
351+
* @param imageIndex index of the image, must be a valid index for the max number of image
352+
* specified by {@link Builder#setMaxImages(int)}.
353+
* @param exifData byte buffer containing a Exif data block.
354+
* @param offset offset of the Exif data block within exifData.
355+
* @param length length of the Exif data block.
356+
*/
357+
@Override
358+
public void addExifData(int imageIndex, @NonNull byte[] exifData, int offset, int length) {
359+
super.addExifData(imageIndex, exifData, offset, length);
360+
}
361+
362+
/**
363+
* Stop the heif writer synchronously. Throws exception if the writer didn't finish writing
364+
* successfully. Upon a success return:
365+
*
366+
* - For buffer and bitmap inputs, all images sent before stop will be written.
367+
*
368+
* - For surface input, images with timestamp on or before that specified in
369+
* {@link #setInputEndOfStreamTimestamp(long)} will be written. In case where
370+
* {@link #setInputEndOfStreamTimestamp(long)} was never called, stop will block
371+
* until maximum number of images are received.
372+
*
373+
* @param timeoutMs Maximum time (in microsec) to wait for the writer to complete, with zero
374+
* indicating waiting indefinitely.
375+
* @see #setInputEndOfStreamTimestamp(long)
376+
* @throws Exception if encountered error, in which case the output file may not be valid. In
377+
* particular, {@link TimeoutException} is thrown when timed out, and {@link
378+
* MediaCodec.CodecException} is thrown when encountered codec error.
379+
*/
380+
@Override
381+
public void stop(@IntRange(from = 0) long timeoutMs) throws Exception {
382+
super.stop(timeoutMs);
383+
}
384+
279385
@SuppressLint("WrongConstant")
280386
@SuppressWarnings("WeakerAccess") /* synthetic access */
281387
HeifWriter(@NonNull String path,

heifwriter/heifwriter/src/main/java/androidx/heifwriter/WriterBase.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ protected WriterBase(int rotation,
159159
*
160160
* @throws IllegalStateException if called more than once.
161161
*/
162-
public void start() {
162+
void start() {
163163
checkStarted(false);
164164
mStarted = true;
165165
mEncoder.start();
@@ -176,7 +176,7 @@ public void start() {
176176
*
177177
* @throws IllegalStateException if not started or not configured to use buffer input.
178178
*/
179-
public void addYuvBuffer(int format, @NonNull byte[] data) {
179+
void addYuvBuffer(int format, @NonNull byte[] data) {
180180
checkStartedAndMode(INPUT_MODE_BUFFER);
181181
synchronized (this) {
182182
if (mEncoder != null) {
@@ -192,7 +192,7 @@ public void addYuvBuffer(int format, @NonNull byte[] data) {
192192
*
193193
* @throws IllegalStateException if called after start or not configured to use surface input.
194194
*/
195-
public @NonNull Surface getInputSurface() {
195+
@NonNull Surface getInputSurface() {
196196
checkStarted(false);
197197
checkMode(INPUT_MODE_SURFACE);
198198
return mEncoder.getInputSurface();
@@ -212,7 +212,7 @@ public void addYuvBuffer(int format, @NonNull byte[] data) {
212212
*
213213
* @throws IllegalStateException if not started or not configured to use surface input.
214214
*/
215-
public void setInputEndOfStreamTimestamp(@IntRange(from = 0) long timestampNs) {
215+
void setInputEndOfStreamTimestamp(@IntRange(from = 0) long timestampNs) {
216216
checkStartedAndMode(INPUT_MODE_SURFACE);
217217
synchronized (this) {
218218
if (mEncoder != null) {
@@ -227,7 +227,7 @@ public void setInputEndOfStreamTimestamp(@IntRange(from = 0) long timestampNs) {
227227
* @param bitmap the bitmap to be added to the file.
228228
* @throws IllegalStateException if not started or not configured to use bitmap input.
229229
*/
230-
public void addBitmap(@NonNull Bitmap bitmap) {
230+
void addBitmap(@NonNull Bitmap bitmap) {
231231
checkStartedAndMode(INPUT_MODE_BITMAP);
232232
synchronized (this) {
233233
if (mEncoder != null) {
@@ -246,7 +246,7 @@ public void addBitmap(@NonNull Bitmap bitmap) {
246246
* @param offset offset of the Exif data block within exifData.
247247
* @param length length of the Exif data block.
248248
*/
249-
public void addExifData(int imageIndex, @NonNull byte[] exifData, int offset, int length) {
249+
void addExifData(int imageIndex, @NonNull byte[] exifData, int offset, int length) {
250250
checkStarted(true);
251251

252252
ByteBuffer buffer = ByteBuffer.allocateDirect(length);
@@ -298,7 +298,7 @@ void processExifData() {
298298
* particular, {@link TimeoutException} is thrown when timed out, and {@link
299299
* MediaCodec.CodecException} is thrown when encountered codec error.
300300
*/
301-
public void stop(@IntRange(from = 0) long timeoutMs) throws Exception {
301+
void stop(@IntRange(from = 0) long timeoutMs) throws Exception {
302302
checkStarted(true);
303303
synchronized (this) {
304304
if (mEncoder != null) {

0 commit comments

Comments
 (0)