Beispiel #1
0
void clip_graph_tracking_values_iterate_track(
        SpaceClip *sc, MovieTrackingTrack *track, void *userdata,
        void (*func)(void *userdata, MovieTrackingTrack *track, MovieTrackingMarker *marker, int coord,
                     int scene_framenr, float val),
        void (*segment_start)(void *userdata, MovieTrackingTrack *track, int coord),
        void (*segment_end)(void *userdata, int coord))
{
	MovieClip *clip = ED_space_clip_get_clip(sc);
	int width, height, coord;

	BKE_movieclip_get_size(clip, &sc->user, &width, &height);

	for (coord = 0; coord < 2; coord++) {
		int i, prevfra = 0;
		bool open = false;
		float prevval = 0.0f;

		for (i = 0; i < track->markersnr; i++) {
			MovieTrackingMarker *marker = &track->markers[i];
			float val;

			if (marker->flag & MARKER_DISABLED) {
				if (open) {
					if (segment_end)
						segment_end(userdata, coord);

					open = false;
				}

				continue;
			}

			if (!open) {
				if (segment_start)
					segment_start(userdata, track, coord);

				open = true;
				prevval = marker->pos[coord];
			}

			/* value is a pixels per frame speed */
			val = (marker->pos[coord] - prevval) * ((coord == 0) ? (width) : (height));
			val /= marker->framenr - prevfra;

			if (func) {
				int scene_framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr);

				func(userdata, track, marker, coord, scene_framenr, val);
			}

			prevval = marker->pos[coord];
			prevfra = marker->framenr;
		}

		if (open) {
			if (segment_end)
				segment_end(userdata, coord);
		}
	}
}
Beispiel #2
0
static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
{
    SegmentContext *seg = s->priv_data;
    AVFormatContext *oc = seg->avf;
    AVStream *st = s->streams[pkt->stream_index];
    int64_t end_pts = seg->recording_time * seg->number;
    int ret, can_split = 1;

    if (!oc)
        return AVERROR(EINVAL);

    if (seg->has_video) {
        can_split = st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
                    pkt->flags & AV_PKT_FLAG_KEY;
    }

    if (can_split && av_compare_ts(pkt->pts, st->time_base, end_pts,
                                   AV_TIME_BASE_Q) >= 0) {
        av_log(s, AV_LOG_DEBUG, "Next segment starts at %d %"PRId64"\n",
               pkt->stream_index, pkt->pts);

        ret = segment_end(oc, seg->individual_header_trailer);

        if (!ret)
            ret = segment_start(s, seg->individual_header_trailer);

        if (ret)
            goto fail;

        oc = seg->avf;

        if (seg->list) {
            if (seg->list_type == LIST_HLS) {
                if ((ret = segment_hls_window(s, 0)) < 0)
                    goto fail;
            } else {
                avio_printf(seg->pb, "%s\n", oc->filename);
                avio_flush(seg->pb);
                if (seg->size && !(seg->number % seg->size)) {
                    ff_format_io_close(s, &seg->pb);
                    if ((ret = s->io_open(s, &seg->pb, seg->list,
                                          AVIO_FLAG_WRITE, NULL)) < 0)
                        goto fail;
                }
            }
        }
    }

    ret = ff_write_chained(oc, pkt->stream_index, pkt, s);

fail:
    if (ret < 0)
        seg_free_context(seg);

    return ret;
}
Beispiel #3
0
int
dwfl_report_segment (Dwfl *dwfl, int ndx, const GElf_Phdr *phdr, GElf_Addr bias,
		     const void *ident)
{
  if (dwfl == NULL)
    return -1;

  if (ndx < 0)
    ndx = dwfl->lookup_tail_ndx;

  if (phdr->p_align > 1 && (dwfl->segment_align <= 1 ||
			    phdr->p_align < dwfl->segment_align))
    dwfl->segment_align = phdr->p_align;

  if (unlikely (dwfl->lookup_module != NULL))
    {
      free (dwfl->lookup_module);
      dwfl->lookup_module = NULL;
    }

  GElf_Addr start = segment_start (dwfl, bias + phdr->p_vaddr);
  GElf_Addr end = segment_end (dwfl, bias + phdr->p_vaddr + phdr->p_memsz);

  /* Coalesce into the last one if contiguous and matching.  */
  if (ndx != dwfl->lookup_tail_ndx
      || ident == NULL
      || ident != dwfl->lookup_tail_ident
      || start != dwfl->lookup_tail_vaddr
      || phdr->p_offset != dwfl->lookup_tail_offset)
    {
      /* Normally just appending keeps us sorted.  */

      size_t i = dwfl->lookup_elts;
      while (i > 0 && unlikely (start < dwfl->lookup_addr[i - 1]))
	--i;

      if (unlikely (insert (dwfl, i, start, end, ndx)))
	{
	  __libdwfl_seterrno (DWFL_E_NOMEM);
	  return -1;
	}
    }

  dwfl->lookup_tail_ident = ident;
  dwfl->lookup_tail_vaddr = end;
  dwfl->lookup_tail_offset = end - bias - phdr->p_vaddr + phdr->p_offset;
  dwfl->lookup_tail_ndx = ndx + 1;

  return ndx;
}
Beispiel #4
0
static bool
reify_segments (Dwfl *dwfl)
{
  int hint = -1;
  for (Dwfl_Module *mod = dwfl->modulelist; mod != NULL; mod = mod->next)
    if (! mod->gc)
      {
	const GElf_Addr start = segment_start (dwfl, mod->low_addr);
	const GElf_Addr end = segment_end (dwfl, mod->high_addr);

	int idx = lookup (dwfl, start, hint);
	if (unlikely (idx < 0))
	  {
	    /* Module starts below any segment.  Insert a low one.  */
	    if (unlikely (insert (dwfl, 0, start, end, -1)))
	      return true;
	    idx = 0;
	  }
	else if (dwfl->lookup_addr[idx] > start)
	  {
	    /* The module starts in the middle of this segment.  Split it.  */
	    if (unlikely (insert (dwfl, idx + 1, start, end,
				  dwfl->lookup_segndx[idx])))
	      return true;
	    ++idx;
	  }
	else if (dwfl->lookup_addr[idx] < start)
	  {
	    /* The module starts past the end of this segment.
	       Add a new one.  */
	    if (unlikely (insert (dwfl, idx + 1, start, end, -1)))
	      return true;
	    ++idx;
	  }

	if ((size_t) idx + 1 < dwfl->lookup_elts
	    && end < dwfl->lookup_addr[idx + 1]
	    /* The module ends in the middle of this segment.  Split it.  */
	    && unlikely (insert (dwfl, idx + 1,
				 end, dwfl->lookup_addr[idx + 1], -1)))
	  return true;

	if (dwfl->lookup_module == NULL)
	  {
	    dwfl->lookup_module = calloc (dwfl->lookup_alloc,
					  sizeof dwfl->lookup_module[0]);
	    if (unlikely (dwfl->lookup_module == NULL))
	      return true;
	  }

	/* Cache a backpointer in the module.  */
	mod->segment = idx;

	/* Put MOD in the table for each segment that's inside it.  */
	do
	  dwfl->lookup_module[idx++] = mod;
	while ((size_t) idx < dwfl->lookup_elts
	       && dwfl->lookup_addr[idx] < end);
	hint = (size_t) idx < dwfl->lookup_elts ? idx : -1;
      }

  return false;
}