Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Unified Diff: source/libvpx/ivfdec.c

Issue 148913004: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « source/libvpx/ivfdec.h ('k') | source/libvpx/ivfenc.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/libvpx/ivfdec.c
===================================================================
--- source/libvpx/ivfdec.c (revision 247498)
+++ source/libvpx/ivfdec.c (working copy)
@@ -8,23 +8,39 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#include "./ivfdec.h"
-
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include "./ivfdec.h"
+
+static const char *IVF_SIGNATURE = "DKIF";
+
+static void fix_framerate(int *num, int *den) {
+ // Some versions of vpxenc used 1/(2*fps) for the timebase, so
+ // we can guess the framerate using only the timebase in this
+ // case. Other files would require reading ahead to guess the
+ // timebase, like we do for webm.
+ if (*num < 1000) {
+ // Correct for the factor of 2 applied to the timebase in the encoder.
+ if (*num & 1)
+ *den *= 2;
+ else
+ *num /= 2;
+ } else {
+ // Don't know FPS for sure, and don't have readahead code
+ // (yet?), so just default to 30fps.
+ *num = 30;
+ *den = 1;
+ }
+}
+
int file_is_ivf(struct VpxInputContext *input_ctx) {
char raw_hdr[32];
int is_ivf = 0;
- // TODO(tomfinegan): This can eventually go away, but for now it's required
- // because the means by which file types are detected differ in vpxdec and
- // vpxenc.
- rewind(input_ctx->file);
-
if (fread(raw_hdr, 1, 32, input_ctx->file) == 32) {
- if (raw_hdr[0] == 'D' && raw_hdr[1] == 'K' &&
- raw_hdr[2] == 'I' && raw_hdr[3] == 'F') {
+ if (memcmp(IVF_SIGNATURE, raw_hdr, 4) == 0) {
is_ivf = 1;
if (mem_get_le16(raw_hdr + 4) != 0) {
@@ -37,27 +53,8 @@
input_ctx->height = mem_get_le16(raw_hdr + 14);
input_ctx->framerate.numerator = mem_get_le32(raw_hdr + 16);
input_ctx->framerate.denominator = mem_get_le32(raw_hdr + 20);
-
- /* Some versions of vpxenc used 1/(2*fps) for the timebase, so
- * we can guess the framerate using only the timebase in this
- * case. Other files would require reading ahead to guess the
- * timebase, like we do for webm.
- */
- if (input_ctx->framerate.numerator < 1000) {
- /* Correct for the factor of 2 applied to the timebase in the
- * encoder.
- */
- if (input_ctx->framerate.numerator & 1)
- input_ctx->framerate.denominator <<= 1;
- else
- input_ctx->framerate.numerator >>= 1;
- } else {
- /* Don't know FPS for sure, and don't have readahead code
- * (yet?), so just default to 30fps.
- */
- input_ctx->framerate.numerator = 30;
- input_ctx->framerate.denominator = 1;
- }
+ fix_framerate(&input_ctx->framerate.numerator,
+ &input_ctx->framerate.denominator);
}
}
@@ -70,17 +67,11 @@
return is_ivf;
}
-int ivf_read_frame(struct VpxInputContext *input_ctx,
- uint8_t **buffer,
- size_t *bytes_read,
- size_t *buffer_size) {
+int ivf_read_frame(FILE *infile, uint8_t **buffer,
+ size_t *bytes_read, size_t *buffer_size) {
char raw_header[IVF_FRAME_HDR_SZ] = {0};
size_t frame_size = 0;
- FILE *infile = input_ctx->file;
- if (input_ctx->file_type != FILE_TYPE_IVF)
- return 0;
-
if (fread(raw_header, IVF_FRAME_HDR_SZ, 1, infile) != 1) {
if (!feof(infile))
warn("Failed to read frame size\n");
@@ -117,3 +108,68 @@
return 1;
}
+
+struct vpx_video {
+ FILE *file;
+ unsigned char *buffer;
+ size_t buffer_size;
+ size_t frame_size;
+ unsigned int fourcc;
+ int width;
+ int height;
+};
+
+vpx_video_t *vpx_video_open_file(FILE *file) {
+ char raw_hdr[32];
+ vpx_video_t *video;
+
+ if (fread(raw_hdr, 1, 32, file) != 32)
+ return NULL; // Can't read file header;
+
+ if (memcmp(IVF_SIGNATURE, raw_hdr, 4) != 0)
+ return NULL; // Wrong IVF signature
+
+ if (mem_get_le16(raw_hdr + 4) != 0)
+ return NULL; // Wrong IVF version
+
+ video = (vpx_video_t *)malloc(sizeof(*video));
+ video->file = file;
+ video->buffer = NULL;
+ video->buffer_size = 0;
+ video->frame_size = 0;
+ video->fourcc = mem_get_le32(raw_hdr + 8);
+ video->width = mem_get_le16(raw_hdr + 12);
+ video->height = mem_get_le16(raw_hdr + 14);
+ return video;
+}
+
+void vpx_video_close(vpx_video_t *video) {
+ if (video) {
+ free(video->buffer);
+ free(video);
+ }
+}
+
+int vpx_video_get_width(vpx_video_t *video) {
+ return video->width;
+}
+
+int vpx_video_get_height(vpx_video_t *video) {
+ return video->height;
+}
+
+unsigned int vpx_video_get_fourcc(vpx_video_t *video) {
+ return video->fourcc;
+}
+
+int vpx_video_read_frame(vpx_video_t *video) {
+ return !ivf_read_frame(video->file, &video->buffer, &video->frame_size,
+ &video->buffer_size);
+}
+
+const unsigned char *vpx_video_get_frame(vpx_video_t *video, size_t *size) {
+ if (size)
+ *size = video->frame_size;
+
+ return video->buffer;
+}
« no previous file with comments | « source/libvpx/ivfdec.h ('k') | source/libvpx/ivfenc.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698