| 168 | } |
| 169 | |
| 170 | static hb_buffer_t * ssa_read( hb_work_private_t * pv ) |
| 171 | { |
| 172 | int err; |
| 173 | hb_buffer_t * out; |
| 174 | |
| 175 | if (pv->job->reader_pts_offset == AV_NOPTS_VALUE) |
| 176 | { |
| 177 | // We need to wait for reader to initialize it's pts offset so that |
| 178 | // we know where to start reading SSA. |
| 179 | return NULL; |
| 180 | } |
| 181 | if (pv->start_time == AV_NOPTS_VALUE) |
| 182 | { |
| 183 | pv->start_time = pv->job->reader_pts_offset; |
| 184 | if (pv->job->pts_to_stop > 0) |
| 185 | { |
| 186 | pv->stop_time = pv->job->pts_to_start + pv->job->pts_to_stop; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | if ((err = av_read_frame(pv->ic, pv->pkt)) < 0) |
| 191 | { |
| 192 | if (err != AVERROR_EOF) |
| 193 | { |
| 194 | hb_error("SSA demux read error %d", err); |
| 195 | } |
| 196 | return hb_buffer_eof_init(); |
| 197 | } |
| 198 | AVStream * st = pv->ic->streams[pv->pkt->stream_index]; |
| 199 | |
| 200 | out = hb_buffer_init(pv->pkt->size + 1); |
| 201 | memcpy(out->data, pv->pkt->data, pv->pkt->size); |
| 202 | out->data[pv->pkt->size] = 0; |
| 203 | out->size = pv->pkt->size; |
| 204 | |
| 205 | double tsconv = (double)90000. * st->time_base.num / st->time_base.den; |
| 206 | if (pv->pkt->pts != AV_NOPTS_VALUE) |
| 207 | { |
| 208 | out->s.start = pv->pkt->pts * tsconv + |
| 209 | pv->subtitle->config.offset * 90; |
| 210 | } |
| 211 | if (pv->pkt->dts != AV_NOPTS_VALUE) |
| 212 | { |
| 213 | out->s.renderOffset = pv->pkt->dts * tsconv + |
| 214 | pv->subtitle->config.offset * 90; |
| 215 | } |
| 216 | if (out->s.renderOffset >= 0 && out->s.start == AV_NOPTS_VALUE) |
| 217 | { |
| 218 | out->s.start = out->s.renderOffset; |
| 219 | } |
| 220 | else if (out->s.renderOffset == AV_NOPTS_VALUE && out->s.start >= 0) |
| 221 | { |
| 222 | out->s.renderOffset = out->s.start; |
| 223 | } |
| 224 | int64_t pkt_duration = pv->pkt->duration; |
| 225 | if (pkt_duration != AV_NOPTS_VALUE) |
| 226 | { |
| 227 | out->s.duration = pkt_duration * tsconv; |
no test coverage detected