| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 warn("Failed to read full frame\n"); | 101 warn("Failed to read full frame\n"); |
| 102 return 1; | 102 return 1; |
| 103 } | 103 } |
| 104 | 104 |
| 105 *bytes_read = frame_size; | 105 *bytes_read = frame_size; |
| 106 return 0; | 106 return 0; |
| 107 } | 107 } |
| 108 | 108 |
| 109 return 1; | 109 return 1; |
| 110 } | 110 } |
| 111 | |
| 112 struct vpx_video { | |
| 113 FILE *file; | |
| 114 unsigned char *buffer; | |
| 115 size_t buffer_size; | |
| 116 size_t frame_size; | |
| 117 unsigned int fourcc; | |
| 118 int width; | |
| 119 int height; | |
| 120 }; | |
| 121 | |
| 122 vpx_video_t *vpx_video_open_file(FILE *file) { | |
| 123 char raw_hdr[32]; | |
| 124 vpx_video_t *video; | |
| 125 | |
| 126 if (fread(raw_hdr, 1, 32, file) != 32) | |
| 127 return NULL; // Can't read file header; | |
| 128 | |
| 129 if (memcmp(IVF_SIGNATURE, raw_hdr, 4) != 0) | |
| 130 return NULL; // Wrong IVF signature | |
| 131 | |
| 132 if (mem_get_le16(raw_hdr + 4) != 0) | |
| 133 return NULL; // Wrong IVF version | |
| 134 | |
| 135 video = (vpx_video_t *)malloc(sizeof(*video)); | |
| 136 video->file = file; | |
| 137 video->buffer = NULL; | |
| 138 video->buffer_size = 0; | |
| 139 video->frame_size = 0; | |
| 140 video->fourcc = mem_get_le32(raw_hdr + 8); | |
| 141 video->width = mem_get_le16(raw_hdr + 12); | |
| 142 video->height = mem_get_le16(raw_hdr + 14); | |
| 143 return video; | |
| 144 } | |
| 145 | |
| 146 void vpx_video_close(vpx_video_t *video) { | |
| 147 if (video) { | |
| 148 free(video->buffer); | |
| 149 free(video); | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 int vpx_video_get_width(vpx_video_t *video) { | |
| 154 return video->width; | |
| 155 } | |
| 156 | |
| 157 int vpx_video_get_height(vpx_video_t *video) { | |
| 158 return video->height; | |
| 159 } | |
| 160 | |
| 161 unsigned int vpx_video_get_fourcc(vpx_video_t *video) { | |
| 162 return video->fourcc; | |
| 163 } | |
| 164 | |
| 165 int vpx_video_read_frame(vpx_video_t *video) { | |
| 166 return !ivf_read_frame(video->file, &video->buffer, &video->frame_size, | |
| 167 &video->buffer_size); | |
| 168 } | |
| 169 | |
| 170 const unsigned char *vpx_video_get_frame(vpx_video_t *video, size_t *size) { | |
| 171 if (size) | |
| 172 *size = video->frame_size; | |
| 173 | |
| 174 return video->buffer; | |
| 175 } | |
| OLD | NEW |