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

Side by Side Diff: source/libvpx/video_reader.c

Issue 168343002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: libvpx: Pull from upstream Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/video_reader.h ('k') | source/libvpx/video_writer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <stdlib.h>
12 #include <string.h>
13
14 #include "./ivfdec.h"
15 #include "./video_reader.h"
16
17 static const char *const kIVFSignature = "DKIF";
18
19 struct VpxVideoReaderStruct {
20 VpxVideoInfo info;
21 FILE *file;
22 uint8_t *buffer;
23 size_t buffer_size;
24 size_t frame_size;
25 };
26
27 VpxVideoReader *vpx_video_reader_open(const char *filename) {
28 char header[32];
29 VpxVideoReader *reader = NULL;
30 FILE *const file = fopen(filename, "rb");
31 if (!file)
32 return NULL; // Can't open file
33
34 if (fread(header, 1, 32, file) != 32)
35 return NULL; // Can't read file header
36
37 if (memcmp(kIVFSignature, header, 4) != 0)
38 return NULL; // Wrong IVF signature
39
40 if (mem_get_le16(header + 4) != 0)
41 return NULL; // Wrong IVF version
42
43 reader = calloc(1, sizeof(*reader));
44 if (!reader)
45 return NULL; // Can't allocate VpxVideoReader
46
47 reader->file = file;
48 reader->info.codec_fourcc = mem_get_le32(header + 8);
49 reader->info.frame_width = mem_get_le16(header + 12);
50 reader->info.frame_height = mem_get_le16(header + 14);
51 reader->info.time_base.numerator = mem_get_le32(header + 16);
52 reader->info.time_base.denominator = mem_get_le32(header + 20);
53
54 return reader;
55 }
56
57 void vpx_video_reader_close(VpxVideoReader *reader) {
58 if (reader) {
59 fclose(reader->file);
60 free(reader->buffer);
61 free(reader);
62 }
63 }
64
65 int vpx_video_reader_read_frame(VpxVideoReader *reader) {
66 return !ivf_read_frame(reader->file, &reader->buffer, &reader->frame_size,
67 &reader->buffer_size);
68 }
69
70 const uint8_t *vpx_video_reader_get_frame(VpxVideoReader *reader,
71 size_t *size) {
72 if (size)
73 *size = reader->frame_size;
74
75 return reader->buffer;
76 }
77
78 const VpxVideoInfo *vpx_video_reader_get_info(VpxVideoReader *reader) {
79 return &reader->info;
80 }
81
OLDNEW
« no previous file with comments | « source/libvpx/video_reader.h ('k') | source/libvpx/video_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698