Example #1
0
		inline void _filter<OSIFrameType, ParentFilterType>::parse(mutable_helper<typename ParentFilterType::frame_type> parent_helper) const
		{
			_base_filter<OSIFrameType>::clear_last_helper();

			if (frame_parent_match<OSIFrameType, typename ParentFilterType::frame_type>(parent_helper))
			{
				try
				{
					mutable_helper<OSIFrameType> helper(parent_helper.payload());

					if (check_frame(helper))
					{
						if (_base_filter<OSIFrameType>::filter_frame(helper))
						{
							if (bridge_filter_frame(parent_helper, helper))
							{
								_base_filter<OSIFrameType>::frame_handled(helper);
							}
						}
					}
				}
				catch (std::logic_error&)
				{
				}
			}
		}
static void
process_input_buf (GstOmxBaseFilter * omx_base_filter, GstBuffer **buf)
{
  GstOmxH264Dec *h264_self;

  h264_self = GST_OMX_H264DEC (omx_base_filter);

  if (h264_self->h264Format == GSTOMX_H264_FORMAT_UNKNOWN) {
    check_frame(h264_self, *buf);
  }

  if (h264_self->h264Format == GSTOMX_H264_FORMAT_3GPP) {

    if (omx_base_filter->last_pad_push_return != GST_FLOW_OK ||
        !(omx_base_filter->gomx->omx_state == OMX_StateExecuting ||
            omx_base_filter->gomx->omx_state == OMX_StatePause)) {
        GST_LOG_OBJECT(h264_self, "this frame will not be converted and go to out_flushing");
        return;
    }

    GST_LOG_OBJECT(h264_self, "H264 format is 3GPP. convert to NALU");
    convert_frame(h264_self, buf);
  }

  GST_OMX_BASE_FILTER_CLASS (parent_class)->process_input_buf (omx_base_filter, buf);
}
Example #3
0
static int action_start(struct sxplayer_ctx *s, int opt_test_flags)
{
    int ret;
    struct sxplayer_frame *frame = sxplayer_get_frame(s, 0);

    if ((ret = check_frame(frame, 0, opt_test_flags)) < 0)
        return ret;
    sxplayer_release_frame(frame);
    return 0;
}
Example #4
0
int has_frame(uint8_t * data, size_t size)
{
    size_t pos = 0;
    while(pos < size)
    {
        if(data[pos] == 0x7E)
            if(check_frame(data+pos, size-pos) == 0)
                return pos;
        ++pos;
    }
    return -1;
}
Example #5
0
/**
 * Repondre a une requete d'un joueur
 * NOTA: cette fonction est bloquante et attend une requete d'un joueur 
 * 
 * @param sock Socket du joueur ayant envoye une requete
 * @param the_players Liste des joueurs
 * @return Resultat de l'echange compose de 2 champs:
 *         - type: correspond le plus souvent au type de trame
 *                 ou a une fin de connexion
 *         - content: correspond au contenu brut de l'echange, a savoir
 *                    une structure Player, un identifiant ou un ordre.
 */
Result* respond(int sock, Players the_players) {
    Result* result = NULL;
    Frame frame = recv_frame(sock);
    
    /*debug*/
    print_frame(frame);
    
    if(check_frame(frame) == SUCCESS) {
        
        /* Deconnexion du joueur */
        if(frame->pennant == SPECIAL_FRAME) {
            result = malloc(sizeof(Result));
            remove_player_by_sock(sock, the_players, 1);
            
            result->type = NOT_CONNECTED;
            result->content = NULL;
        
        /* Traitement du serveur a la requete du client */
        } else {
            switch(frame->id) {      
                case Connect:
                    result = respond_connect(sock, the_players, frame);
                    break;

                case Initiate:
                    result = respond_initiate(sock, the_players, frame);
                    break;

                case Order:
                    result = respond_order(sock, the_players, frame);
                    break;
                
                /* Type de trame inconnu ou non autorisee du protocole 
                 * @todo si type de trame existant, renvoyer une erreur specifique
                 */
                default:
                    PRINT_UNKNOWN_FRAME_TYPE(frame->id);
                    break;
            }
        }
    }
    
    if(frame != NULL) {
        free_frame(frame);
    }
    
    return result;
}
Example #6
0
static int action_middle(struct sxplayer_ctx *s, int opt_test_flags)
{
    int ret;
    struct sxplayer_frame *f0 = sxplayer_get_frame(s, 30.0);
    struct sxplayer_frame *f1 = sxplayer_get_frame(s, 30.1);
    struct sxplayer_frame *f2 = sxplayer_get_frame(s, 30.2);
    struct sxplayer_frame *f3 = sxplayer_get_frame(s, 15.0);
    struct sxplayer_frame *f4 = sxplayer_get_next_frame(s);
    struct sxplayer_frame *f5 = sxplayer_get_next_frame(s);
    const double increment = opt_test_flags & FLAG_AUDIO ? SOURCE_SPF/(float)SOURCE_FREQ
                             : 1./SOURCE_FPS;

    if ((ret = check_frame(f0, 30.0,               opt_test_flags)) < 0 ||
            (ret = check_frame(f1, 30.1,               opt_test_flags)) < 0 ||
            (ret = check_frame(f2, 30.2,               opt_test_flags)) < 0 ||
            (ret = check_frame(f3, 15.0,               opt_test_flags)) < 0 ||
            (ret = check_frame(f4, 15.0 + 1*increment, opt_test_flags)) < 0 ||
            (ret = check_frame(f5, 15.0 + 2*increment, opt_test_flags)) < 0)
        return ret;

    sxplayer_release_frame(f0);
    sxplayer_release_frame(f5);
    sxplayer_release_frame(f1);
    sxplayer_release_frame(f4);
    sxplayer_release_frame(f2);
    sxplayer_release_frame(f3);

    f0 = sxplayer_get_next_frame(s);
    f1 = sxplayer_get_frame(s, 16.0);
    f2 = sxplayer_get_frame(s, 16.001);

    if ((ret = check_frame(f0, 15.0 + 3*increment, opt_test_flags)) < 0 ||
            (ret = check_frame(f1, 16.0,               opt_test_flags)) < 0)
        return ret;

    if (f2) {
        fprintf(stderr, "got f2\n");
        return -1;
    }

    sxplayer_release_frame(f1);
    sxplayer_release_frame(f0);

    return 0;
}
Example #7
0
		inline void _base_filter<OSIFrameType>::do_parse(boost::asio::mutable_buffer buf) const
		{
			try
			{
				mutable_helper<OSIFrameType> helper(buf);

				if (check_frame(helper))
				{
					if (_base_filter<OSIFrameType>::filter_frame(helper))
					{
						_base_filter<OSIFrameType>::frame_handled(helper);
					}
				}
			}
			catch (std::logic_error&)
			{
			}
		}
Example #8
0
File: rarpd.c Project: afett/rarpd
void handle_request(int fd, struct link *link, bool check_bootable)
{
	memset(link->buf, 0, sizeof(link->buf));
	memset(&link->src, 0, sizeof(link->src));

	ssize_t size = read_request(fd,
		&link->src, link->buf, sizeof(link->buf));

	if (size <= 0) {
		return;
	}

	if (!check_frame(&link->src, link)) {
		return;
	}

	if ((size_t) size < sizeof(struct ether_arp)) {
		XLOG_WARNING("request to short");
		return;
	}

	struct ether_arp *arp_req = (struct ether_arp *)link->buf;
	if (!check_request(arp_req, &link->src)) {
		return;
	}

	struct in_addr ip;
	memset(&ip, 0, sizeof(in_addr_t));
	int ret = resolve((struct ether_addr*)&arp_req->arp_tha, &ip);
	if (ret != 0) {
		return;
	}

	XLOG_DEBUG("found address: %s", inet_ntoa(ip));
	if (check_bootable == true && !is_bootable(ip)) {
		return;
	}

	create_reply(arp_req, &ip, link);
	dispatcher_flags(&link->handler, POLLOUT);
}
Example #9
0
int main(int argc, char *argv[])
{
	int fd;
	int res, x;
	struct dahdi_params tp;
	struct dahdi_bufferinfo bi;
	int bs = BLOCK_SIZE;
	int pos = 0;
	unsigned char inbuf[BLOCK_SIZE];
	unsigned char outbuf[BLOCK_SIZE];
	int bytes = 0;
	int out;
	unsigned int olddata1;
	int oldones1;
	int oldbits1;
	unsigned int olddata = 0;
	int oldones = 0;
	int oldbits = 0;
	int hdlcmode = 0;
	struct fasthdlc_state fs;
	if (argc < 2) {
		fprintf(stderr, "Usage: %s <DAHDI device>\n", argv[0]);
		exit(1);
	}
	fd = open(argv[1], O_RDWR, 0600);
	if (fd < 0) {
		fprintf(stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
		exit(1);
	}
	if (ioctl(fd, DAHDI_SET_BLOCKSIZE, &bs)) {
		fprintf(stderr, "Unable to set block size to %d: %s\n", bs, strerror(errno));
		exit(1);
	}
	if (ioctl(fd, DAHDI_GET_PARAMS, &tp)) {
		fprintf(stderr, "Unable to get channel parameters\n");
		exit(1);
	}
	if ((tp.sigtype & DAHDI_SIG_HDLCRAW) == DAHDI_SIG_HDLCRAW) {
		printf("In HDLC mode\n");
		hdlcmode = 1;
	} else if ((tp.sigtype & DAHDI_SIG_CLEAR) == DAHDI_SIG_CLEAR) {
		printf("In CLEAR mode\n");
		hdlcmode = 0;
	} else {
		fprintf(stderr, "Not in a reasonable mode\n");
		exit(1);
	}
	res = ioctl(fd, DAHDI_GET_BUFINFO, &bi);
	if (!res) {
		bi.txbufpolicy = DAHDI_POLICY_IMMEDIATE;
		bi.rxbufpolicy = DAHDI_POLICY_IMMEDIATE;
		bi.numbufs = 4;
		res = ioctl(fd, DAHDI_SET_BUFINFO, &bi);
		if (res < 0) {
			fprintf(stderr, "Unable to set buf info: %s\n", strerror(errno));
			exit(1);
		}
	} else {
		fprintf(stderr, "Unable to get buf info: %s\n", strerror(errno));
		exit(1);
	}
	ioctl(fd, DAHDI_GETEVENT);
	fasthdlc_precalc();
	fasthdlc_init(&fs, FASTHDLC_MODE_64);
	for (;;) {
		res = read(fd, outbuf, sizeof(outbuf));
		if (hdlcmode) {
			if (res < 0) {
				if (errno == ELAST) {
					if (ioctl(fd, DAHDI_GETEVENT, &x) < 0) {
						fprintf(stderr, "Unaable to get event: %s\n", strerror(errno));
						exit(1);
					}
					fprintf(stderr, "Event: %d (%d bytes since last error)\n", x, bytes);
					bytes = 0;
					continue;
				} else {
					fprintf(stderr, "Error: %s\n", strerror(errno));
					exit(1);
				}
			}
#if 0
			printf("Res is %d, buf0 is %d, buf1 is %d\n", res, outbuf[0], outbuf[1]);
#endif
			if (res < 2) {
				fprintf(stderr, "Too small?  Only got %d bytes\n", res);
			}
			check_frame(outbuf, res);
		} else {
			for (x = 0; x < res; x++) {
				oldones1 = oldones;
				oldbits1 = oldbits;
				olddata1 = olddata;
				oldones = fs.ones;
				oldbits = fs.bits;
				olddata = fs.data;
				fasthdlc_rx_load(&fs, outbuf[x]);
				out = fasthdlc_rx_run(&fs);
				if (out & RETURN_EMPTY_FLAG) {
					/* Empty */
				} else if (out & RETURN_COMPLETE_FLAG) {
					if (pos && (pos < 2)) {
						printf("Too short? (%d)\n", pos);
					} else if (pos) {
						check_frame(inbuf, pos);
					}
					pos = 0;
				} else if (out & RETURN_DISCARD_FLAG) {
					printf("Discard (search = %d, len = %d, buf = %d, x=%d, res=%d, oldones: %d, oldbits: %d)\n",
						   c, pos, inbuf[0], x, res, oldones, oldbits);
					dump_bitslong(olddata, oldbits);
					printf("Discard                                                 oldones: %d, oldbits: %d)\n",
						   oldones1, oldbits1);
					dump_bitslong(olddata1, oldbits1);
					if (x > 64) {
						dump_bits(outbuf + x - 64, 64);
						dump_bits(outbuf + x, 64);
					}
					pos = 0;
				} else {
					if ((out != c) && (pos < c) && !pos) {
						printf("Warning: Expecting %d at pos %d, got %d (x =%d)\n", c, pos, out, x);
						if (x > 64) {
							dump_bits(outbuf + x - 64, 64);
							dump_bits(outbuf + x, 64);
						}
					}
					inbuf[pos++] = out;
				}
			}
		}
	}

}
Example #10
0
code_block *frame_code(stack_frame *frame)
{
	check_frame(frame);
	return (code_block *)frame->xt - 1;
}
Example #11
0
stack_frame *frame_successor(stack_frame *frame)
{
	check_frame(frame);
	return (stack_frame *)((cell)frame - frame->size);
}
Example #12
0
code_block *factor_vm::frame_code(stack_frame *frame)
{
	check_frame(frame);
	return (code_block *)frame->entry_point - 1;
}
Example #13
0
/*
  isdnhdlc_decode - decodes HDLC frames from a transparent bit stream.

  The source buffer is scanned for valid HDLC frames looking for
  flags (01111110) to indicate the start of a frame. If the start of
  the frame is found, the bit stuffing is removed (0 after 5 1's).
  When a new flag is found, the complete frame has been received
  and the CRC is checked.
  If a valid frame is found, the function returns the frame length
  excluding the CRC with the bit HDLC_END_OF_FRAME set.
  If the beginning of a valid frame is found, the function returns
  the length.
  If a framing error is found (too many 1s and not a flag) the function
  returns the length with the bit HDLC_FRAMING_ERROR set.
  If a CRC error is found the function returns the length with the
  bit HDLC_CRC_ERROR set.
  If the frame length exceeds the destination buffer size, the function
  returns the length with the bit HDLC_LENGTH_ERROR set.

  src - source buffer
  slen - source buffer length
  count - number of bytes removed (decoded) from the source buffer
  dst _ destination buffer
  dsize - destination buffer size
  returns - number of decoded bytes in the destination buffer and status
  flag.
*/
int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src, int slen,
		    int *count, u8 *dst, int dsize)
{
	int status = 0;

	static const unsigned char fast_flag[] = {
		0x00, 0x00, 0x00, 0x20, 0x30, 0x38, 0x3c, 0x3e, 0x3f
	};

	static const unsigned char fast_flag_value[] = {
		0x00, 0x7e, 0xfc, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3f
	};

	static const unsigned char fast_abort[] = {
		0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
	};

#define handle_fast_flag(h)						\
	do {								\
		if (h->cbin == fast_flag[h->bit_shift]) {		\
			h->ffvalue = fast_flag_value[h->bit_shift];	\
			h->state = HDLC_FAST_FLAG;			\
			h->ffbit_shift = h->bit_shift;			\
			h->bit_shift = 1;				\
		} else {						\
			h->state = HDLC_GET_DATA;			\
			h->data_received = 0;				\
		}							\
	} while (0)

#define handle_abort(h)						\
	do {							\
		h->shift_reg = fast_abort[h->ffbit_shift - 1];	\
		h->hdlc_bits1 = h->ffbit_shift - 2;		\
		if (h->hdlc_bits1 < 0)				\
			h->hdlc_bits1 = 0;			\
		h->data_bits = h->ffbit_shift - 1;		\
		h->state = HDLC_GET_DATA;			\
		h->data_received = 0;				\
	} while (0)

	*count = slen;

	while (slen > 0) {
		if (hdlc->bit_shift == 0) {
			/* the code is for bitreverse streams */
			if (hdlc->do_bitreverse == 0)
				hdlc->cbin = bitrev8(*src++);
			else
				hdlc->cbin = *src++;
			slen--;
			hdlc->bit_shift = 8;
			if (hdlc->do_adapt56)
				hdlc->bit_shift--;
		}

		switch (hdlc->state) {
		case STOPPED:
			return 0;
		case HDLC_FAST_IDLE:
			if (hdlc->cbin == 0xff) {
				hdlc->bit_shift = 0;
				break;
			}
			hdlc->state = HDLC_GET_FLAG_B0;
			hdlc->hdlc_bits1 = 0;
			hdlc->bit_shift = 8;
			break;
		case HDLC_GET_FLAG_B0:
			if (!(hdlc->cbin & 0x80)) {
				hdlc->state = HDLC_GETFLAG_B1A6;
				hdlc->hdlc_bits1 = 0;
			} else {
				if ((!hdlc->do_adapt56) &&
				    (++hdlc->hdlc_bits1 >= 8) &&
				    (hdlc->bit_shift == 1))
					hdlc->state = HDLC_FAST_IDLE;
			}
			hdlc->cbin <<= 1;
			hdlc->bit_shift--;
			break;
		case HDLC_GETFLAG_B1A6:
			if (hdlc->cbin & 0x80) {
				hdlc->hdlc_bits1++;
				if (hdlc->hdlc_bits1 == 6)
					hdlc->state = HDLC_GETFLAG_B7;
			} else
				hdlc->hdlc_bits1 = 0;
			hdlc->cbin <<= 1;
			hdlc->bit_shift--;
			break;
		case HDLC_GETFLAG_B7:
			if (hdlc->cbin & 0x80) {
				hdlc->state = HDLC_GET_FLAG_B0;
			} else {
				hdlc->state = HDLC_GET_DATA;
				hdlc->crc = 0xffff;
				hdlc->shift_reg = 0;
				hdlc->hdlc_bits1 = 0;
				hdlc->data_bits = 0;
				hdlc->data_received = 0;
			}
			hdlc->cbin <<= 1;
			hdlc->bit_shift--;
			break;
		case HDLC_GET_DATA:
			if (hdlc->cbin & 0x80) {
				hdlc->hdlc_bits1++;
				switch (hdlc->hdlc_bits1) {
				case 6:
					break;
				case 7:
					if (hdlc->data_received)
						/* bad frame */
						status = -HDLC_FRAMING_ERROR;
					if (!hdlc->do_adapt56) {
						if (hdlc->cbin == fast_abort
						    [hdlc->bit_shift + 1]) {
							hdlc->state =
								HDLC_FAST_IDLE;
							hdlc->bit_shift = 1;
							break;
						}
					} else
						hdlc->state = HDLC_GET_FLAG_B0;
					break;
				default:
					hdlc->shift_reg >>= 1;
					hdlc->shift_reg |= 0x80;
					hdlc->data_bits++;
					break;
				}
			} else {
				switch (hdlc->hdlc_bits1) {
				case 5:
					break;
				case 6:
					if (hdlc->data_received)
						status = check_frame(hdlc);
					hdlc->crc = 0xffff;
					hdlc->shift_reg = 0;
					hdlc->data_bits = 0;
					if (!hdlc->do_adapt56)
						handle_fast_flag(hdlc);
					else {
						hdlc->state = HDLC_GET_DATA;
						hdlc->data_received = 0;
					}
					break;
				default:
					hdlc->shift_reg >>= 1;
					hdlc->data_bits++;
					break;
				}
				hdlc->hdlc_bits1 = 0;
			}
			if (status) {
				hdlc->dstpos = 0;
				*count -= slen;
				hdlc->cbin <<= 1;
				hdlc->bit_shift--;
				return status;
			}
			if (hdlc->data_bits == 8) {
				hdlc->data_bits = 0;
				hdlc->data_received = 1;
				hdlc->crc = crc_ccitt_byte(hdlc->crc,
							   hdlc->shift_reg);

				/* good byte received */
				if (hdlc->dstpos < dsize)
					dst[hdlc->dstpos++] = hdlc->shift_reg;
				else {
					/* frame too long */
					status = -HDLC_LENGTH_ERROR;
					hdlc->dstpos = 0;
				}
			}
			hdlc->cbin <<= 1;
			hdlc->bit_shift--;
			break;
		case HDLC_FAST_FLAG:
			if (hdlc->cbin == hdlc->ffvalue) {
				hdlc->bit_shift = 0;
				break;
			} else {
				if (hdlc->cbin == 0xff) {
					hdlc->state = HDLC_FAST_IDLE;
					hdlc->bit_shift = 0;
				} else if (hdlc->ffbit_shift == 8) {
					hdlc->state = HDLC_GETFLAG_B7;
					break;
				} else
					handle_abort(hdlc);
			}
			break;
		default:
			break;
		}
Example #14
0
		Map::size_type Map::set_frame(size_type size)
		{
			return m_frame = check_frame(size);
		}
Example #15
0
		Map::Map(const Facade & wf, size_type size, bool write) :
			m_size(simstd::min(wf.size(), size)), m_frame(check_frame(DEFAULT_FRAME)), m_map(CheckHandle(::CreateFileMapping(wf, nullptr, (write) ? PAGE_READWRITE : PAGE_READONLY,
					high_part_64(m_size), low_part_64(m_size), nullptr))),
			m_write(write) {
			}