ref: 5c2640cdff7dd3a2af6ce5294de8d7a36a18f1eb
parent: a8cc9885ea0165d3cc925542aafb89cb613a46f2
author: Jean-Marc Valin <[email protected]>
date: Tue May 2 07:53:59 EDT 2017
Implement ope_flush_header()
--- a/include/opusenc.h
+++ b/include/opusenc.h
@@ -53,6 +53,7 @@
#define OPE_UNIMPLEMENTED -11
#define OPE_BAD_ARG -12
#define OPE_INTERNAL_ERROR -13
+#define OPE_TOO_LATE -14
/* These are the "raw" request values -- they should usually not be used. */
#define OPE_SET_DECISION_DELAY_REQUEST 14000
@@ -122,6 +123,9 @@
/** Sets the Opus comment vendor string (optional, defaults to library info). */
OPE_EXPORT int ope_set_vendor_string(OggOpusEnc *enc, const char *vendor);
+
+/** Write out the header now rather than wait for audio to begin. */
+OPE_EXPORT int ope_flush_header(OggOpusEnc *enc);
/** Goes straight to the libopus ctl() functions. */
OPE_EXPORT int ope_encoder_ctl(OggOpusEnc *enc, int request, ...);
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -452,6 +452,7 @@
/* Add a comment to the file (can only be called before encoding samples). */
int ope_add_comment(OggOpusEnc *enc, const char *tag, const char *val) {
+ if (enc->stream_is_init) return OPE_TOO_LATE;
if (comment_add(&enc->comment, &enc->comment_length, tag, val)) return OPE_INTERNAL_ERROR;
return OPE_OK;
}
@@ -459,6 +460,7 @@
int ope_add_picture(OggOpusEnc *enc, const char *spec) {
const char *error_message;
char *picture_data;
+ if (enc->stream_is_init) return OPE_TOO_LATE;
picture_data = parse_picture_specification(spec, &error_message, &enc->seen_file_icons);
if(picture_data==NULL){
/* FIXME: return proper errors rather than printing a message. */
@@ -472,9 +474,15 @@
/* Sets the Opus comment vendor string (optional, defaults to library info). */
int ope_set_vendor_string(OggOpusEnc *enc, const char *vendor) {
+ if (enc->stream_is_init) return OPE_TOO_LATE;
(void)enc;
(void)vendor;
return OPE_UNIMPLEMENTED;
+}
+
+int ope_flush_header(OggOpusEnc *enc) {
+ if (enc->stream_is_init) return OPE_TOO_LATE;
+ else init_stream(enc);
}
/* Goes straight to the libopus ctl() functions. */