comparison x265_glue.c @ 34:5d51fff843eb default tip

A "commit dump" of random changes I've made, as I probably won't be touching this code anymore.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 08 Mar 2020 19:18:48 +0200
parents 33594243ce31
children
comparison
equal deleted inserted replaced
33:33594243ce31 34:5d51fff843eb
146 s->buf_len += data_len; 146 s->buf_len += data_len;
147 } 147 }
148 148
149 static int x265_encode(HEVCEncoderContext *s, Image *img) 149 static int x265_encode(HEVCEncoderContext *s, Image *img)
150 { 150 {
151 int c_count, i, ret; 151 int ret;
152 x265_picture *pic;
153 uint32_t nal_count; 152 uint32_t nal_count;
154 x265_nal *p_nal; 153 x265_nal *p_nal;
155 pic = s->pic; 154 x265_picture *pic = s->pic;
156 155 int c_count = (img->format == BPG_FORMAT_GRAY) ? 1 : 3;
157 if (img->format == BPG_FORMAT_GRAY) 156
158 c_count = 1; 157 for (int i = 0; i < c_count; i++) {
159 else
160 c_count = 3;
161 for(i = 0; i < c_count; i++) {
162 pic->planes[i] = img->data[i]; 158 pic->planes[i] = img->data[i];
163 pic->stride[i] = img->linesize[i]; 159 pic->stride[i] = img->linesize[i];
164 } 160 }
165 pic->bitDepth = img->bit_depth; 161 pic->bitDepth = img->bit_depth;
166 162
167 ret = s->api->encoder_encode(s->enc, &p_nal, &nal_count, pic, NULL); 163 ret = s->api->encoder_encode(s->enc, &p_nal, &nal_count, pic, NULL);
168 if (ret > 0) { 164 if (ret > 0) {
169 for(i = 0; i < nal_count; i++) { 165 for(uint32_t i = 0; i < nal_count; i++) {
170 add_nal(s, p_nal[i].payload, p_nal[i].sizeBytes); 166 add_nal(s, p_nal[i].payload, p_nal[i].sizeBytes);
171 } 167 }
172 } 168 }
173 return 0; 169 return 0;
174 } 170 }
175 171
176 static int x265_close(HEVCEncoderContext *s, uint8_t **pbuf) 172 static int x265_close(HEVCEncoderContext *s, uint8_t **pbuf)
177 { 173 {
178 int buf_len, ret, i; 174 int buf_len, ret;
179 uint32_t nal_count; 175 uint32_t nal_count;
180 x265_nal *p_nal; 176 x265_nal *p_nal;
181 177
182 /* get last compressed pictures */ 178 /* get last compressed pictures */
183 for(;;) { 179 for(;;) {
184 ret = s->api->encoder_encode(s->enc, &p_nal, &nal_count, NULL, NULL); 180 ret = s->api->encoder_encode(s->enc, &p_nal, &nal_count, NULL, NULL);
185 if (ret <= 0) 181 if (ret <= 0)
186 break; 182 break;
187 for(i = 0; i < nal_count; i++) { 183 for (uint32_t i = 0; i < nal_count; i++) {
188 add_nal(s, p_nal[i].payload, p_nal[i].sizeBytes); 184 add_nal(s, p_nal[i].payload, p_nal[i].sizeBytes);
189 } 185 }
190 } 186 }
191 187
192 if (s->buf_len < s->buf_size) { 188 if (s->buf_len < s->buf_size) {