summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2009-09-22 14:51:30 +0200
committerWim Taymans <wim@metal.(none)>2009-09-28 22:16:50 +0200
commit1b325945e579cc9ed32953ab1f2d036e61c68de7 (patch)
tree77fee3c7c395b6524b7a4166e3ec56751b7340a6
parentc199b1d039c1f8673829d6465b08de7a537658ca (diff)
avi: remove code that got converted
-rw-r--r--gst/avi/gstavidemux.c404
1 files changed, 0 insertions, 404 deletions
diff --git a/gst/avi/gstavidemux.c b/gst/avi/gstavidemux.c
index 42d5ce5d1..3233c5bd3 100644
--- a/gst/avi/gstavidemux.c
+++ b/gst/avi/gstavidemux.c
@@ -2238,189 +2238,6 @@ out_of_mem:
2238 } 2238 }
2239} 2239}
2240 2240
2241#if 0
2242/*
2243 * gst_avi_demux_parse_index:
2244 * @avi: calling element (used for debugging/errors).
2245 * @buf: buffer containing the full index.
2246 * @entries_list: list (returned by this function) containing the index
2247 * entries parsed from the buffer. The first in the list
2248 * is also a pointer to the allocated data and should be
2249 * free'ed at some point.
2250 *
2251 * Read index entries from the provided buffer. Takes ownership of @buf.
2252 * The buffer should contain a GST_RIFF_TAG_idx1 chunk.
2253 */
2254static void
2255gst_avi_demux_parse_index (GstAviDemux * avi,
2256 GstBuffer * buf, GList ** _entries_list)
2257{
2258 guint64 pos_before = avi->offset;
2259 gst_avi_index_entry *entries = NULL;
2260 guint8 *data;
2261 GList *entries_list = NULL;
2262 guint i, num, n;
2263#ifndef GST_DISABLE_GST_DEBUG
2264 gulong _nr_keyframes = 0;
2265#endif
2266 GstClockTime stamp;
2267
2268 if (!buf || !GST_BUFFER_SIZE (buf)) {
2269 *_entries_list = NULL;
2270 GST_DEBUG ("empty index");
2271 if (buf)
2272 gst_buffer_unref (buf);
2273 return;
2274 }
2275
2276 stamp = gst_util_get_timestamp ();
2277
2278 data = GST_BUFFER_DATA (buf);
2279 num = GST_BUFFER_SIZE (buf) / sizeof (gst_riff_index_entry);
2280 if (!(entries = g_try_new (gst_avi_index_entry, num)))
2281 goto out_of_mem;
2282
2283 GST_INFO_OBJECT (avi, "Parsing index, nr_entries = %6d", num);
2284
2285 for (i = 0, n = 0; i < num; i++) {
2286 gint64 next_ts;
2287 gst_riff_index_entry entry, *_entry;
2288 GstAviStream *stream;
2289 guint stream_nr;
2290 gst_avi_index_entry *target;
2291
2292 _entry = &((gst_riff_index_entry *) data)[i];
2293 entry.id = GST_READ_UINT32_LE (&_entry->id);
2294 entry.offset = GST_READ_UINT32_LE (&_entry->offset);
2295 entry.flags = GST_READ_UINT32_LE (&_entry->flags);
2296 entry.size = GST_READ_UINT32_LE (&_entry->size);
2297 target = &entries[n];
2298
2299 if (entry.id == GST_RIFF_rec || entry.id == 0 ||
2300 (entry.offset == 0 && n > 0))
2301 continue;
2302
2303 stream_nr = CHUNKID_TO_STREAMNR (entry.id);
2304 if (stream_nr >= avi->num_streams) {
2305 GST_WARNING_OBJECT (avi,
2306 "Index entry %d has invalid stream nr %d", i, stream_nr);
2307 continue;
2308 }
2309 target->stream_nr = stream_nr;
2310 stream = &avi->stream[stream_nr];
2311
2312 if (!stream->strh) {
2313 GST_WARNING_OBJECT (avi, "Unhandled stream %d, skipping", stream_nr);
2314 continue;
2315 }
2316
2317 target->index_nr = i;
2318 target->flags =
2319 (entry.flags & GST_RIFF_IF_KEYFRAME) ? GST_AVI_INDEX_ENTRY_FLAG_KEYFRAME
2320 : 0;
2321 target->size = entry.size;
2322 target->offset = entry.offset + 8;
2323
2324 /* figure out if the index is 0 based or relative to the MOVI start */
2325 if (n == 0) {
2326 if (target->offset < pos_before)
2327 avi->index_offset = pos_before + 8;
2328 else
2329 avi->index_offset = 0;
2330 GST_DEBUG ("index_offset = %" G_GUINT64_FORMAT, avi->index_offset);
2331 }
2332
2333 if (stream->strh->type == GST_RIFF_FCC_auds) {
2334 /* all audio frames are keyframes */
2335 target->flags |= GST_AVI_INDEX_ENTRY_FLAG_KEYFRAME;
2336 }
2337#ifndef GST_DISABLE_GST_DEBUG
2338 if (target->flags & GST_AVI_INDEX_ENTRY_FLAG_KEYFRAME)
2339 _nr_keyframes++;
2340#endif
2341
2342 /* stream duration unknown, now we can calculate it */
2343 if (stream->idx_duration == -1)
2344 stream->idx_duration = 0;
2345
2346 /* timestamps */
2347 target->ts = stream->idx_duration;
2348 if (stream->is_vbr) {
2349 /* VBR stream next timestamp */
2350 if (stream->strh->type == GST_RIFF_FCC_auds) {
2351 next_ts = avi_stream_convert_frames_to_time_unchecked (stream,
2352 stream->total_blocks + 1);
2353 } else {
2354 next_ts = avi_stream_convert_frames_to_time_unchecked (stream,
2355 stream->idx_n + 1);
2356 }
2357 } else {
2358 /* constant rate stream */
2359 next_ts = avi_stream_convert_bytes_to_time_unchecked (stream,
2360 stream->total_bytes + target->size);
2361 }
2362 /* duration is next - current */
2363 target->dur = next_ts - target->ts;
2364
2365 /* stream position */
2366 target->bytes_before = stream->total_bytes;
2367 target->frames_before = stream->idx_n;
2368
2369 stream->total_bytes += target->size;
2370 stream->idx_n++;
2371 if (stream->strh->type == GST_RIFF_FCC_auds) {
2372 if (stream->strf.auds->blockalign > 0)
2373 stream->total_blocks +=
2374 (target->size + stream->strf.auds->blockalign -
2375 1) / stream->strf.auds->blockalign;
2376 else
2377 stream->total_blocks++;
2378 }
2379 stream->idx_duration = next_ts;
2380
2381 GST_LOG_OBJECT (avi,
2382 "Adding index entry %d (%6u), flags %02x, stream %d, size %u "
2383 ", offset %" G_GUINT64_FORMAT ", time %" GST_TIME_FORMAT ", dur %"
2384 GST_TIME_FORMAT,
2385 target->index_nr, stream->idx_n - 1, target->flags,
2386 target->stream_nr, target->size, target->offset,
2387 GST_TIME_ARGS (target->ts), GST_TIME_ARGS (target->dur));
2388 entries_list = g_list_prepend (entries_list, target);
2389
2390 n++;
2391 }
2392
2393 GST_INFO_OBJECT (avi, "Parsed index, %6u/%6u entries, %5lu keyframes, "
2394 "entry size = %2u, total size = %10u", n, num, _nr_keyframes,
2395 (guint) sizeof (gst_avi_index_entry),
2396 (guint) (n * sizeof (gst_avi_index_entry)));
2397
2398 gst_buffer_unref (buf);
2399
2400 if (n > 0) {
2401 *_entries_list = g_list_reverse (entries_list);
2402 } else {
2403 g_free (entries);
2404 }
2405
2406 stamp = gst_util_get_timestamp () - stamp;
2407 GST_CAT_DEBUG (GST_CAT_PERFORMANCE, "parsing index %" GST_TIME_FORMAT,
2408 GST_TIME_ARGS (stamp));
2409
2410 return;
2411
2412 /* ERRORS */
2413out_of_mem:
2414 {
2415 GST_ELEMENT_ERROR (avi, RESOURCE, NO_SPACE_LEFT, (NULL),
2416 ("Cannot allocate memory for %u*%u=%u bytes",
2417 (guint) sizeof (gst_avi_index_entry), num,
2418 (guint) sizeof (gst_avi_index_entry) * num));
2419 gst_buffer_unref (buf);
2420 }
2421}
2422#endif
2423
2424/* 2241/*
2425 * gst_avi_demux_stream_index: 2242 * gst_avi_demux_stream_index:
2426 * @avi: avi demuxer object. 2243 * @avi: avi demuxer object.
@@ -4241,218 +4058,6 @@ done:
4241 return ret; 4058 return ret;
4242} 4059}
4243 4060
4244#if 0
4245/*
4246 * Read data from one index entry
4247 */
4248static GstFlowReturn
4249gst_avi_demux_process_next_entry (GstAviDemux * avi)
4250{
4251 GstFlowReturn res = GST_FLOW_OK;
4252 gboolean processed = FALSE;
4253 GstAviStream *stream;
4254 gst_avi_index_entry *entry;
4255 GstBuffer *buf;
4256
4257 do {
4258 /* see if we are at the end */
4259 if ((avi->segment.rate > 0 && avi->current_entry >= avi->index_size))
4260 goto eos;
4261
4262 /* get next entry, this will work as we checked for the index size above */
4263 entry = &avi->index_entries[avi->current_entry++];
4264
4265 /* check for reverse playback */
4266 if (avi->segment.rate < 0 && avi->current_entry > avi->reverse_stop_index) {
4267 GST_LOG_OBJECT (avi, "stop_index %d reached", avi->reverse_stop_index);
4268
4269 /* check if we have pushed enough data for this segment */
4270 if (avi->reverse_start_index == 0)
4271 goto eos_reverse_zero;
4272 if (avi->index_entries[avi->reverse_start_index].ts < avi->segment.start)
4273 goto eos_reverse_segment;
4274
4275 if (!(entry = gst_avi_demux_step_reverse (avi)))
4276 goto eos;
4277
4278 avi->current_entry++;
4279 }
4280
4281 /* see if we have a valid stream, ignore if not
4282 * FIXME: can't we check this when building the index?
4283 * we check it in _parse_index(), _stream_scan()
4284 */
4285 if (entry->stream_nr >= avi->num_streams) {
4286 GST_WARNING_OBJECT (avi,
4287 "Entry %d has non-existing stream nr %d",
4288 avi->current_entry - 1, entry->stream_nr);
4289 continue;
4290 }
4291
4292 /* get stream now */
4293 stream = &avi->stream[entry->stream_nr];
4294
4295 if (avi->segment.rate > 0.0) {
4296 /* only check this for fowards playback for now */
4297 if ((entry->flags & GST_AVI_INDEX_ENTRY_FLAG_KEYFRAME)
4298 && GST_CLOCK_TIME_IS_VALID (entry->ts)
4299 && GST_CLOCK_TIME_IS_VALID (avi->segment.stop)
4300 && (entry->ts > avi->segment.stop)) {
4301 goto eos_stop;
4302 }
4303 }
4304
4305 /* skip empty entries */
4306 if (entry->size == 0 || !stream->pad) {
4307 GST_DEBUG_OBJECT (avi, "Skipping entry %d (%d, %p)",
4308 avi->current_entry - 1, entry->size, stream->pad);
4309 goto next;
4310 }
4311
4312 GST_LOG ("reading buffer (size=%d) from stream %d at current pos %"
4313 G_GUINT64_FORMAT " (%llx)", entry->size, entry->stream_nr,
4314 avi->index_offset + entry->offset, avi->index_offset + entry->offset);
4315
4316 /* pull in the data */
4317 res = gst_pad_pull_range (avi->sinkpad, entry->offset +
4318 avi->index_offset, entry->size, &buf);
4319 if (res != GST_FLOW_OK)
4320 goto pull_failed;
4321
4322 /* check for short buffers, this is EOS as well */
4323 if (GST_BUFFER_SIZE (buf) < entry->size)
4324 goto short_buffer;
4325
4326 /* invert the picture if needed */
4327 buf = gst_avi_demux_invert (stream, buf);
4328
4329 /* mark non-keyframes */
4330 if (!(entry->flags & GST_AVI_INDEX_ENTRY_FLAG_KEYFRAME))
4331 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
4332
4333 GST_BUFFER_TIMESTAMP (buf) = entry->ts;
4334 GST_BUFFER_DURATION (buf) = entry->dur;
4335 if (stream->strh->type == GST_RIFF_FCC_vids) {
4336 if (stream->current_frame >= 0)
4337 GST_BUFFER_OFFSET (buf) = stream->current_frame;
4338 else {
4339 gint64 framenum;
4340 GstFormat fmt = GST_FORMAT_DEFAULT;
4341
4342 if (gst_pad_query_convert (stream->pad, GST_FORMAT_TIME, entry->ts,
4343 &fmt, &framenum))
4344 GST_BUFFER_OFFSET (buf) = framenum;
4345 else
4346 GST_BUFFER_OFFSET (buf) = GST_BUFFER_OFFSET_NONE;
4347 }
4348 } else
4349 GST_BUFFER_OFFSET (buf) = GST_BUFFER_OFFSET_NONE;
4350 GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET_NONE;
4351 gst_buffer_set_caps (buf, GST_PAD_CAPS (stream->pad));
4352
4353 GST_DEBUG_OBJECT (avi, "Pushing buffer of size %d, offset %"
4354 G_GUINT64_FORMAT " and time %"
4355 GST_TIME_FORMAT " on pad %s",
4356 GST_BUFFER_SIZE (buf), GST_BUFFER_OFFSET (buf),
4357 GST_TIME_ARGS (entry->ts), GST_PAD_NAME (stream->pad));
4358
4359 /* update current position in the segment */
4360 gst_segment_set_last_stop (&avi->segment, GST_FORMAT_TIME, entry->ts);
4361
4362 /* mark discont when pending */
4363 if (stream->discont) {
4364 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
4365 stream->discont = FALSE;
4366 }
4367
4368 res = gst_pad_push (stream->pad, buf);
4369
4370 /* mark as processed, we increment the frame and byte counters then
4371 * leave the while loop and return the GstFlowReturn */
4372 processed = TRUE;
4373 GST_DEBUG_OBJECT (avi, "Processed buffer %d: %s", entry->index_nr,
4374 gst_flow_get_name (res));
4375
4376 if (avi->segment.rate < 0
4377 && entry->ts > avi->segment.stop && res == GST_FLOW_UNEXPECTED) {
4378 /* In reverse playback we can get a GST_FLOW_UNEXPECTED when
4379 * we are at the end of the segment, so we just need to jump
4380 * back to the previous section.
4381 */
4382 GST_DEBUG_OBJECT (avi, "downstream has reached end of segment");
4383
4384 if (!(entry = gst_avi_demux_step_reverse (avi)))
4385 goto eos;
4386
4387 res = GST_FLOW_OK;
4388
4389 stream->current_frame = entry->frames_before;
4390 stream->current_byte = entry->bytes_before;
4391
4392 continue;
4393 }
4394
4395 /* combine flows */
4396 res = gst_avi_demux_combine_flows (avi, stream, res);
4397
4398 next:
4399 stream->current_frame = entry->frames_before + 1;
4400 stream->current_byte = entry->bytes_before + entry->size;
4401 } while (!processed);
4402
4403beach:
4404 GST_DEBUG_OBJECT (avi, "returning %s", gst_flow_get_name (res));
4405
4406 return res;
4407
4408 /* ERRORS */
4409eos:
4410 {
4411 GST_LOG_OBJECT (avi, "Handled last index entry, setting EOS (%d > %d)",
4412 avi->current_entry, avi->index_size);
4413 /* we mark the first stream as EOS */
4414 res = GST_FLOW_UNEXPECTED;
4415 goto beach;
4416 }
4417eos_stop:
4418 {
4419 GST_LOG_OBJECT (avi, "Found keyframe after segment,"
4420 " setting EOS (%" GST_TIME_FORMAT " > %" GST_TIME_FORMAT ")",
4421 GST_TIME_ARGS (entry->ts), GST_TIME_ARGS (avi->segment.stop));
4422 res = GST_FLOW_UNEXPECTED;
4423 goto beach;
4424 }
4425eos_reverse_zero:
4426 {
4427 GST_DEBUG_OBJECT (avi, "start_index was 0, setting EOS");
4428 res = GST_FLOW_UNEXPECTED;
4429 goto beach;
4430 }
4431eos_reverse_segment:
4432 {
4433 GST_DEBUG_OBJECT (avi, "full segment pushed, setting EOS");
4434 res = GST_FLOW_UNEXPECTED;
4435 goto beach;
4436 }
4437pull_failed:
4438 {
4439 GST_DEBUG_OBJECT (avi,
4440 "pull range failed: pos=%" G_GUINT64_FORMAT " size=%d",
4441 entry->offset + avi->index_offset, entry->size);
4442 goto beach;
4443 }
4444short_buffer:
4445 {
4446 GST_WARNING_OBJECT (avi, "Short read at offset %" G_GUINT64_FORMAT
4447 ", only got %d/%d bytes (truncated file?)", entry->offset +
4448 avi->index_offset, GST_BUFFER_SIZE (buf), entry->size);
4449 gst_buffer_unref (buf);
4450 res = GST_FLOW_UNEXPECTED;
4451 goto beach;
4452 }
4453}
4454#endif
4455
4456/* move @stream to the next position in its index */ 4061/* move @stream to the next position in its index */
4457static GstFlowReturn 4062static GstFlowReturn
4458gst_avi_demux_advance (GstAviDemux * avi, GstAviStream * stream, 4063gst_avi_demux_advance (GstAviDemux * avi, GstAviStream * stream,
@@ -4705,15 +4310,6 @@ short_buffer:
4705 ret = GST_FLOW_UNEXPECTED; 4310 ret = GST_FLOW_UNEXPECTED;
4706 goto beach; 4311 goto beach;
4707 } 4312 }
4708#if 0
4709eos_stream:
4710 {
4711 GST_DEBUG_OBJECT (avi, "No samples left for stream");
4712 /* EOS will be raised if all are EOS */
4713 ret = GST_FLOW_OK;
4714 goto beach;
4715 }
4716#endif
4717} 4313}
4718 4314
4719/* 4315/*