Commit 4b1794ff authored by Rafaël Carré's avatar Rafaël Carré

opus_header: remove dependency on libopus

We might need to generate Opus headers without actually encoding anything
parent 313e7a26
...@@ -641,7 +641,7 @@ static int OpenEncoder(vlc_object_t *p_this) ...@@ -641,7 +641,7 @@ static int OpenEncoder(vlc_object_t *p_this)
/* Now that we have preskip, we can write the header to extradata */ /* Now that we have preskip, we can write the header to extradata */
if (opus_write_header((uint8_t **) &enc->fmt_out.p_extra, if (opus_write_header((uint8_t **) &enc->fmt_out.p_extra,
&enc->fmt_out.i_extra, &header)) &enc->fmt_out.i_extra, &header, opus_get_version_string()))
{ {
msg_Err(enc, "Failed to write header."); msg_Err(enc, "Failed to write header.");
status = VLC_ENOMEM; status = VLC_ENOMEM;
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#endif #endif
#include "opus_header.h" #include "opus_header.h"
#include <opus.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -236,11 +235,12 @@ The comment header is decoded as follows: ...@@ -236,11 +235,12 @@ The comment header is decoded as follows:
7) done. 7) done.
*/ */
static char *comment_init(size_t *length) static char *comment_init(size_t *length, const char *vendor)
{ {
/*The 'vendor' field should be the actual encoding library used.*/ /*The 'vendor' field should be the actual encoding library used.*/
const char *vendor_string = opus_get_version_string(); if (!vendor)
int vendor_length = strlen(vendor_string); vendor = "unknown";
int vendor_length = strlen(vendor);
int user_comment_list_length = 0; int user_comment_list_length = 0;
int len = 8 + 4 + vendor_length + 4; int len = 8 + 4 + vendor_length + 4;
...@@ -250,7 +250,7 @@ static char *comment_init(size_t *length) ...@@ -250,7 +250,7 @@ static char *comment_init(size_t *length)
memcpy(p, "OpusTags", 8); memcpy(p, "OpusTags", 8);
SetDWLE(p + 8, vendor_length); SetDWLE(p + 8, vendor_length);
memcpy(p + 12, vendor_string, vendor_length); memcpy(p + 12, vendor, vendor_length);
SetDWLE(p + 12 + vendor_length, user_comment_list_length); SetDWLE(p + 12 + vendor_length, user_comment_list_length);
*length = len; *length = len;
...@@ -367,7 +367,7 @@ static int opus_header_to_packet(const OpusHeader *h, unsigned char *packet, int ...@@ -367,7 +367,7 @@ static int opus_header_to_packet(const OpusHeader *h, unsigned char *packet, int
return p.pos; return p.pos;
} }
int opus_write_header(uint8_t **p_extra, int *i_extra, OpusHeader *header) int opus_write_header(uint8_t **p_extra, int *i_extra, OpusHeader *header, const char *vendor)
{ {
unsigned char header_data[100]; unsigned char header_data[100];
const int packet_size = opus_header_to_packet(header, header_data, const int packet_size = opus_header_to_packet(header, header_data,
...@@ -380,7 +380,7 @@ int opus_write_header(uint8_t **p_extra, int *i_extra, OpusHeader *header) ...@@ -380,7 +380,7 @@ int opus_write_header(uint8_t **p_extra, int *i_extra, OpusHeader *header)
size[0] = packet_size; size[0] = packet_size;
size_t comments_length; size_t comments_length;
char *comments = comment_init(&comments_length); char *comments = comment_init(&comments_length, vendor);
if (!comments) if (!comments)
return 1; return 1;
if (comment_add(&comments, &comments_length, "ENCODER=", if (comment_add(&comments, &comments_length, "ENCODER=",
......
...@@ -45,6 +45,6 @@ typedef struct { ...@@ -45,6 +45,6 @@ typedef struct {
int opus_header_parse(const unsigned char *header, int len, OpusHeader *h); int opus_header_parse(const unsigned char *header, int len, OpusHeader *h);
int opus_prepare_header(unsigned channels, unsigned rate, OpusHeader *header); int opus_prepare_header(unsigned channels, unsigned rate, OpusHeader *header);
int opus_write_header(uint8_t **p_extra, int *i_extra, OpusHeader *header); int opus_write_header(uint8_t **p_extra, int *i_extra, OpusHeader *header, const char *vendor);
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment