/* read comment and post as tag */ static inline gboolean gst_jpeg_parse_com (GstJpegParse * parse, GstByteReader * reader) { const guint8 *data = NULL; guint16 size = 0; gchar *comment; if (!gst_byte_reader_get_uint16_be (reader, &size)) return FALSE; size -= 2; if (!gst_byte_reader_get_data (reader, size, &data)) return FALSE; comment = get_utf8_from_data (data, size); if (comment) { GstTagList *taglist = get_tag_list (parse); gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_COMMENT, comment, NULL); GST_DEBUG_OBJECT (parse, "collected tags: %" GST_PTR_FORMAT, taglist); g_free (comment); } return TRUE; }
/* *************************************************************** discard, from the num occurrences which are in occ_list, those which are not enclosed in a pair of opening/closing tag return the number of survived occurrences *************************************************************** */ int get_enclosed_occ(occ_data *occ_list, int num_occ, char *tag, bwi_out *s) { int *get_tag_list(char *, bwi_out *, int *); int i, t, status, occ_accepted, tags_seen, num_tags, *tag_list; if(Verbose>1) fprintf(stderr,"%d occurrences to be filtered\n",num_occ); /* ---- the tag list has a very special format (see below) ---- */ tag_list = get_tag_list(tag,s,&num_tags); if(num_tags==0) num_occ = 0; else { assert(tag_list!=NULL); /* ---- find which occ are enclosed between two tags --- */ occ_accepted = tags_seen = 0; status = 0; for(i=0;i<num_occ;i++) { for( ;tags_seen < num_tags; ) { t=tag_list[tags_seen]; if((t>>1) > occ_list[i].pos) break; else { status = t & 1; //get current status in the lsb tags_seen++; } } if(status) occ_list[occ_accepted++] = occ_list[i]; } free(tag_list); num_occ = occ_accepted; // update number of words } // num_tags==0
static gboolean gst_jpeg_parse_sink_event (GstPad * pad, GstEvent * event) { GstJpegParse *parse; gboolean res = TRUE; parse = GST_JPEG_PARSE (gst_pad_get_parent (pad)); GST_DEBUG_OBJECT (parse, "event : %s", GST_EVENT_TYPE_NAME (event)); switch (GST_EVENT_TYPE (event)) { case GST_EVENT_FLUSH_STOP: parse->priv->next_ts = GST_CLOCK_TIME_NONE; parse->priv->duration = GST_CLOCK_TIME_NONE; parse->priv->last_offset = 0; parse->priv->last_entropy_len = 0; parse->priv->last_resync = FALSE; gst_adapter_clear (parse->priv->adapter); break; case GST_EVENT_EOS:{ /* Push the remaining data, even though it's incomplete */ guint available = gst_adapter_available (parse->priv->adapter); if (available > 0) gst_jpeg_parse_push_buffer (parse, available); res = gst_pad_push_event (parse->priv->srcpad, event); break; } case GST_EVENT_NEWSEGMENT: /* Discard any data in the adapter. There should have been an EOS before * to flush it. */ gst_adapter_clear (parse->priv->adapter); res = gst_pad_push_event (parse->priv->srcpad, event); parse->priv->new_segment = TRUE; break; case GST_EVENT_TAG:{ if (!parse->priv->new_segment) res = gst_pad_event_default (pad, event); else { GstTagList *taglist = NULL; gst_event_parse_tag (event, &taglist); /* Hold on to the tags till the srcpad caps are definitely set */ gst_tag_list_insert (get_tag_list (parse), taglist, GST_TAG_MERGE_REPLACE); GST_DEBUG ("collected tags: %" GST_PTR_FORMAT, parse->priv->tags); gst_event_unref (event); } break; } default: res = gst_pad_event_default (pad, event); break; } gst_object_unref (parse); return res; }
static int tag_cmplt(BW *bw) { if (!tag_word_list) tag_word_list = get_tag_list(); if (!tag_word_list) { ttputc(7); return 0; } return simple_cmplt(bw,tag_word_list); }