update nestegg, support vp9
This commit is contained in:
parent
feb469d863
commit
142e478c51
4 changed files with 907 additions and 142 deletions
4
Makefile
4
Makefile
|
@ -13,10 +13,10 @@ FLAGS += -I. -Isrc -Isrc/halloc
|
||||||
|
|
||||||
INSTALL = install
|
INSTALL = install
|
||||||
|
|
||||||
INCLUDEFLAGS ?= `pkg-config --cflags oggplay` `imlib2-config --cflags`
|
INCLUDEFLAGS ?= `pkg-config --cflags oggplay vpx` `imlib2-config --cflags`
|
||||||
LINKFLAGS += -L${PREFIX}/lib
|
LINKFLAGS += -L${PREFIX}/lib
|
||||||
LINKFLAGS += `imlib2-config --libs`
|
LINKFLAGS += `imlib2-config --libs`
|
||||||
LINKFLAGS += `pkg-config --libs oggplay` -lvpx
|
LINKFLAGS += `pkg-config --libs oggplay vpx`
|
||||||
LINKFLAGS += ${LDFLAGS}
|
LINKFLAGS += ${LDFLAGS}
|
||||||
LINKFLAGS += -lm
|
LINKFLAGS += -lm
|
||||||
|
|
||||||
|
|
918
src/nestegg.c
918
src/nestegg.c
File diff suppressed because it is too large
Load diff
|
@ -4,12 +4,12 @@
|
||||||
* This program is made available under an ISC-style license. See the
|
* This program is made available under an ISC-style license. See the
|
||||||
* accompanying file LICENSE for details.
|
* accompanying file LICENSE for details.
|
||||||
*/
|
*/
|
||||||
#ifndef NESTEGG_671cac2a_365d_ed69_d7a3_4491d3538d79
|
#if !defined(NESTEGG_671cac2a_365d_ed69_d7a3_4491d3538d79)
|
||||||
#define NESTEGG_671cac2a_365d_ed69_d7a3_4491d3538d79
|
#define NESTEGG_671cac2a_365d_ed69_d7a3_4491d3538d79
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -67,6 +67,8 @@ extern "C" {
|
||||||
|
|
||||||
#define NESTEGG_CODEC_VP8 0 /**< Track uses Google On2 VP8 codec. */
|
#define NESTEGG_CODEC_VP8 0 /**< Track uses Google On2 VP8 codec. */
|
||||||
#define NESTEGG_CODEC_VORBIS 1 /**< Track uses Xiph Vorbis codec. */
|
#define NESTEGG_CODEC_VORBIS 1 /**< Track uses Xiph Vorbis codec. */
|
||||||
|
#define NESTEGG_CODEC_VP9 2 /**< Track uses Google On2 VP9 codec. */
|
||||||
|
#define NESTEGG_CODEC_OPUS 3 /**< Track uses Xiph Opus codec. */
|
||||||
|
|
||||||
#define NESTEGG_VIDEO_MONO 0 /**< Track is mono video. */
|
#define NESTEGG_VIDEO_MONO 0 /**< Track is mono video. */
|
||||||
#define NESTEGG_VIDEO_STEREO_LEFT_RIGHT 1 /**< Track is side-by-side stereo video. Left first. */
|
#define NESTEGG_VIDEO_STEREO_LEFT_RIGHT 1 /**< Track is side-by-side stereo video. Left first. */
|
||||||
|
@ -131,6 +133,7 @@ typedef struct {
|
||||||
unsigned int crop_top; /**< Pixels to crop from the top of the frame. */
|
unsigned int crop_top; /**< Pixels to crop from the top of the frame. */
|
||||||
unsigned int crop_left; /**< Pixels to crop from the left of the frame. */
|
unsigned int crop_left; /**< Pixels to crop from the left of the frame. */
|
||||||
unsigned int crop_right; /**< Pixels to crop from the right of the frame. */
|
unsigned int crop_right; /**< Pixels to crop from the right of the frame. */
|
||||||
|
unsigned int alpha_mode; /**< 1 if an additional opacity stream is available, otherwise 0. */
|
||||||
} nestegg_video_params;
|
} nestegg_video_params;
|
||||||
|
|
||||||
/** Parameters specific to an audio track. */
|
/** Parameters specific to an audio track. */
|
||||||
|
@ -138,6 +141,8 @@ typedef struct {
|
||||||
double rate; /**< Sampling rate in Hz. */
|
double rate; /**< Sampling rate in Hz. */
|
||||||
unsigned int channels; /**< Number of audio channels. */
|
unsigned int channels; /**< Number of audio channels. */
|
||||||
unsigned int depth; /**< Bits per sample. */
|
unsigned int depth; /**< Bits per sample. */
|
||||||
|
uint64_t codec_delay; /**< Nanoseconds that must be discarded from the start. */
|
||||||
|
uint64_t seek_preroll;/**< Nanoseconds that must be discarded after a seek. */
|
||||||
} nestegg_audio_params;
|
} nestegg_audio_params;
|
||||||
|
|
||||||
/** Logging callback function pointer. */
|
/** Logging callback function pointer. */
|
||||||
|
@ -149,9 +154,10 @@ typedef void (* nestegg_log)(nestegg * context, unsigned int severity, char cons
|
||||||
@param context Storage for the new nestegg context. @see nestegg_destroy
|
@param context Storage for the new nestegg context. @see nestegg_destroy
|
||||||
@param io User supplied IO context.
|
@param io User supplied IO context.
|
||||||
@param callback Optional logging callback function pointer. May be NULL.
|
@param callback Optional logging callback function pointer. May be NULL.
|
||||||
|
@param max_offset Optional maximum offset to be read. Set -1 to ignore.
|
||||||
@retval 0 Success.
|
@retval 0 Success.
|
||||||
@retval -1 Error. */
|
@retval -1 Error. */
|
||||||
int nestegg_init(nestegg ** context, nestegg_io io, nestegg_log callback);
|
int nestegg_init(nestegg ** context, nestegg_io io, nestegg_log callback, int64_t max_offset);
|
||||||
|
|
||||||
/** Destroy a nestegg context and free associated memory.
|
/** Destroy a nestegg context and free associated memory.
|
||||||
@param context #nestegg context to be freed. @see nestegg_init */
|
@param context #nestegg context to be freed. @see nestegg_init */
|
||||||
|
@ -180,6 +186,29 @@ int nestegg_tstamp_scale(nestegg * context, uint64_t * scale);
|
||||||
@retval -1 Error. */
|
@retval -1 Error. */
|
||||||
int nestegg_track_count(nestegg * context, unsigned int * tracks);
|
int nestegg_track_count(nestegg * context, unsigned int * tracks);
|
||||||
|
|
||||||
|
/** Query the start and end offset for a particular cluster.
|
||||||
|
@param context Stream context initialized by #nestegg_init.
|
||||||
|
@param cluster_num Zero-based cluster number; order they appear in cues.
|
||||||
|
@param max_offset Optional maximum offset to be read. Set -1 to ignore.
|
||||||
|
@param start_pos Starting offset of the cluster. -1 means non-existant.
|
||||||
|
@param end_pos Starting offset of the cluster. -1 means non-existant or
|
||||||
|
final cluster.
|
||||||
|
@param tstamp Starting timestamp of the cluster.
|
||||||
|
@retval 0 Success.
|
||||||
|
@retval -1 Error. */
|
||||||
|
int nestegg_get_cue_point(nestegg * context, unsigned int cluster_num,
|
||||||
|
int64_t max_offset, int64_t * start_pos,
|
||||||
|
int64_t * end_pos, uint64_t * tstamp);
|
||||||
|
|
||||||
|
/** Seek to @a offset. Stream will seek directly to offset.
|
||||||
|
Should be used to seek to the start of a resync point, i.e. cluster; the
|
||||||
|
parser will not be able to understand other offsets.
|
||||||
|
@param context Stream context initialized by #nestegg_init.
|
||||||
|
@param offset Absolute offset in bytes.
|
||||||
|
@retval 0 Success.
|
||||||
|
@retval -1 Error. */
|
||||||
|
int nestegg_offset_seek(nestegg * context, uint64_t offset);
|
||||||
|
|
||||||
/** Seek @a track to @a tstamp. Stream seek will terminate at the earliest
|
/** Seek @a track to @a tstamp. Stream seek will terminate at the earliest
|
||||||
key point in the stream at or before @a tstamp. Other tracks in the
|
key point in the stream at or before @a tstamp. Other tracks in the
|
||||||
stream will output packets with unspecified but nearby timestamps.
|
stream will output packets with unspecified but nearby timestamps.
|
||||||
|
@ -248,6 +277,16 @@ int nestegg_track_video_params(nestegg * context, unsigned int track,
|
||||||
int nestegg_track_audio_params(nestegg * context, unsigned int track,
|
int nestegg_track_audio_params(nestegg * context, unsigned int track,
|
||||||
nestegg_audio_params * params);
|
nestegg_audio_params * params);
|
||||||
|
|
||||||
|
/** Query the default frame duration for @a track. For a video track, this
|
||||||
|
is typically the inverse of the video frame rate.
|
||||||
|
@param context Stream context initialized by #nestegg_init.
|
||||||
|
@param track Zero based track number.
|
||||||
|
@param duration Storage for the default duration in nanoseconds.
|
||||||
|
@retval 0 Success.
|
||||||
|
@retval -1 Error. */
|
||||||
|
int nestegg_track_default_duration(nestegg * context, unsigned int track,
|
||||||
|
uint64_t * duration);
|
||||||
|
|
||||||
/** Read a packet of media data. A packet consists of one or more chunks of
|
/** Read a packet of media data. A packet consists of one or more chunks of
|
||||||
data associated with a single track. nestegg_read_packet should be
|
data associated with a single track. nestegg_read_packet should be
|
||||||
called in a loop while the return value is 1 to drive the stream parser
|
called in a loop while the return value is 1 to drive the stream parser
|
||||||
|
@ -277,6 +316,13 @@ int nestegg_packet_track(nestegg_packet * packet, unsigned int * track);
|
||||||
@retval -1 Error. */
|
@retval -1 Error. */
|
||||||
int nestegg_packet_tstamp(nestegg_packet * packet, uint64_t * tstamp);
|
int nestegg_packet_tstamp(nestegg_packet * packet, uint64_t * tstamp);
|
||||||
|
|
||||||
|
/** Query the duration in nanoseconds of @a packet.
|
||||||
|
@param packet Packet initialized by #nestegg_read_packet.
|
||||||
|
@param duration Storage for the queried duration in nanoseconds.
|
||||||
|
@retval 0 Success.
|
||||||
|
@retval -1 Error. */
|
||||||
|
int nestegg_packet_duration(nestegg_packet * packet, uint64_t * duration);
|
||||||
|
|
||||||
/** Query the number of data chunks contained in @a packet.
|
/** Query the number of data chunks contained in @a packet.
|
||||||
@param packet Packet initialized by #nestegg_read_packet.
|
@param packet Packet initialized by #nestegg_read_packet.
|
||||||
@param count Storage for the queried timestamp in nanoseconds.
|
@param count Storage for the queried timestamp in nanoseconds.
|
||||||
|
@ -295,7 +341,50 @@ int nestegg_packet_count(nestegg_packet * packet, unsigned int * count);
|
||||||
int nestegg_packet_data(nestegg_packet * packet, unsigned int item,
|
int nestegg_packet_data(nestegg_packet * packet, unsigned int item,
|
||||||
unsigned char ** data, size_t * length);
|
unsigned char ** data, size_t * length);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
/** Get a pointer to additional data with identifier @a id of additional packet
|
||||||
|
data. If @a id isn't present in the packet, returns -1.
|
||||||
|
@param packet Packet initialized by #nestegg_read_packet.
|
||||||
|
@param id Codec specific identifer. For VP8, use 1 to get a VP8 encoded
|
||||||
|
frame containing an alpha channel in its Y plane.
|
||||||
|
@param data Storage for the queried data pointer.
|
||||||
|
The data is owned by the #nestegg_packet packet.
|
||||||
|
@param length Storage for the queried data size.
|
||||||
|
@retval 0 Success.
|
||||||
|
@retval -1 Error. */
|
||||||
|
int nestegg_packet_additional_data(nestegg_packet * packet, unsigned int id,
|
||||||
|
unsigned char ** data, size_t * length);
|
||||||
|
|
||||||
|
/** Returns discard_padding for given packet
|
||||||
|
@param packet Packet initialized by #nestegg_read_packet.
|
||||||
|
@param discard_padding pointer to store discard padding in.
|
||||||
|
@retval 0 Success.
|
||||||
|
@retval -1 Error. */
|
||||||
|
int nestegg_packet_discard_padding(nestegg_packet * packet,
|
||||||
|
int64_t * discard_padding);
|
||||||
|
|
||||||
|
/** Query the presence of cues.
|
||||||
|
@param context Stream context initialized by #nestegg_init.
|
||||||
|
@retval 0 The media has no cues.
|
||||||
|
@retval 1 The media has cues. */
|
||||||
|
int nestegg_has_cues(nestegg * context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to determine if the buffer looks like the beginning of a WebM file.
|
||||||
|
*
|
||||||
|
* @param buffer A buffer containing the beginning of a media file.
|
||||||
|
* @param length The size of the buffer.
|
||||||
|
* @retval 0 The file is not a WebM file.
|
||||||
|
* @retval 1 The file is a WebM file. */
|
||||||
|
int nestegg_sniff(unsigned char const * buffer, size_t length);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the underlying allocation function for library allocations.
|
||||||
|
*
|
||||||
|
* @param realloc_func The desired function.
|
||||||
|
*/
|
||||||
|
void nestegg_set_halloc_func(void * (* realloc_func)(void *, size_t));
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,6 @@
|
||||||
#include "vpx/vpx_decoder.h"
|
#include "vpx/vpx_decoder.h"
|
||||||
#include "vpx/vp8dx.h"
|
#include "vpx/vp8dx.h"
|
||||||
|
|
||||||
#define interface (&vpx_codec_vp8_dx_algo)
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
@ -361,9 +359,11 @@ int extract_frame_webm(oxstate *state) {
|
||||||
}
|
}
|
||||||
io.userdata = fp;
|
io.userdata = fp;
|
||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
r = nestegg_init(&ctx, io, log_callback);
|
r = nestegg_init(&ctx, io, log_callback, -1);
|
||||||
if (r != 0)
|
if (r != 0) {
|
||||||
return EXIT_FAILURE;
|
fprintf (stderr, "nestegg_init failed %d\n", r);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
nestegg_track_count(ctx, &tracks);
|
nestegg_track_count(ctx, &tracks);
|
||||||
nestegg_duration(ctx, &duration);
|
nestegg_duration(ctx, &duration);
|
||||||
|
@ -373,15 +373,25 @@ int extract_frame_webm(oxstate *state) {
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize codec */
|
|
||||||
if(vpx_codec_dec_init(&codec, interface, NULL, flags))
|
|
||||||
die_codec(&codec, "Failed to initialize decoder");
|
|
||||||
|
|
||||||
for (i = 0; i < tracks; ++i) {
|
for (i = 0; i < tracks; ++i) {
|
||||||
type = nestegg_track_type(ctx, i);
|
type = nestegg_track_type(ctx, i);
|
||||||
codec_id = nestegg_track_codec_id(ctx, i);
|
codec_id = nestegg_track_codec_id(ctx, i);
|
||||||
|
|
||||||
if (type == NESTEGG_TRACK_VIDEO && codec_id == NESTEGG_CODEC_VP8) {
|
if (type == NESTEGG_TRACK_VIDEO) {
|
||||||
|
/* Initialize codec */
|
||||||
|
if (codec_id == NESTEGG_CODEC_VP8) {
|
||||||
|
if(vpx_codec_dec_init(&codec, &vpx_codec_vp8_dx_algo, NULL, flags))
|
||||||
|
die_codec(&codec, "Failed to initialize decoder");
|
||||||
|
#ifdef HAVE_VP9
|
||||||
|
} else if (codec_id == NESTEGG_CODEC_VP9) {
|
||||||
|
if(vpx_codec_dec_init(&codec, &vpx_codec_vp9_dx_algo, NULL, flags))
|
||||||
|
die_codec(&codec, "Failed to initialize decoder");
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "unsupported video codec %d\n", codec_id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
nestegg_track_video_params(ctx, i, &vparams);
|
nestegg_track_video_params(ctx, i, &vparams);
|
||||||
|
|
||||||
if(!nestegg_track_seek(ctx, i, seek_tstamp)) {
|
if(!nestegg_track_seek(ctx, i, seek_tstamp)) {
|
||||||
|
|
Loading…
Reference in a new issue