static int parse_cmdline(char *devname, char *szstart, char *szlength) { char *buffer; unsigned long devstart; unsigned long devlength; if ((!devname) || (!szstart) || (!szlength)) { unregister_devices(); return(-EINVAL); } devstart = simple_strtoul(szstart, &buffer, 0); devstart = handle_unit(devstart, buffer); if (*(szlength) != '+') { devlength = simple_strtoul(szlength, &buffer, 0); devlength = handle_unit(devlength, buffer) - devstart; } else { devlength = simple_strtoul(szlength + 1, &buffer, 0); devlength = handle_unit(devlength, buffer); } T("slram: devname=%s, devstart=0x%lx, devlength=0x%lx\n", devname, devstart, devlength); if ((devstart < 0) || (devlength < 0) || (devlength % SLRAM_BLK_SZ != 0)) { E("slram: Illegal start / length parameter.\n"); return(-EINVAL); } if ((devstart = register_device(devname, devstart, devlength))){ unregister_devices(); return((int)devstart); } return(0); }
void dirac::es_parser_c::flush() { if (m_unparsed_buffer && (4 <= m_unparsed_buffer->get_size())) { uint32_t marker = get_uint32_be(m_unparsed_buffer->get_buffer()); if (DIRAC_SYNC_WORD == marker) handle_unit(memory_c::clone(m_unparsed_buffer->get_buffer(), m_unparsed_buffer->get_size())); } m_unparsed_buffer.reset(); flush_frame(); }
void dirac::es_parser_c::add_bytes(unsigned char *buffer, size_t size) { memory_slice_cursor_c cursor; bool previous_found = false; size_t previous_pos = 0; int64_t previous_stream_pos = m_stream_pos; if (m_unparsed_buffer && (0 != m_unparsed_buffer->get_size())) cursor.add_slice(m_unparsed_buffer); cursor.add_slice(buffer, size); if (3 <= cursor.get_remaining_size()) { uint32_t marker = (1 << 24) | ((unsigned int)cursor.get_char() << 16) | ((unsigned int)cursor.get_char() << 8) | (unsigned int)cursor.get_char(); while (1) { if (DIRAC_SYNC_WORD == marker) { if (!previous_found) { previous_found = true; previous_pos = cursor.get_position() - 4; m_stream_pos = previous_stream_pos + previous_pos; if (!cursor.char_available()) break; marker <<= 8; marker |= (unsigned int)cursor.get_char(); continue; } unsigned char offset_buffer[4]; cursor.copy(offset_buffer, previous_pos + 4 + 1, 4); uint32_t next_offset = get_uint32_be(offset_buffer); if ((0 == next_offset) || ((previous_pos + next_offset) <= (cursor.get_position() - 4))) { int new_size = cursor.get_position() - 4 - previous_pos; memory_cptr packet = memory_c::alloc(new_size); cursor.copy(packet->get_buffer(), previous_pos, new_size); handle_unit(packet); previous_pos = cursor.get_position() - 4; m_stream_pos = previous_stream_pos + previous_pos; } } if (!cursor.char_available()) break; marker <<= 8; marker |= (unsigned int)cursor.get_char(); } } unsigned int new_size = cursor.get_size() - previous_pos; if (0 != new_size) { memory_cptr new_unparsed_buffer = memory_c::alloc(new_size); cursor.copy(new_unparsed_buffer->get_buffer(), previous_pos, new_size); m_unparsed_buffer = new_unparsed_buffer; } else m_unparsed_buffer.reset(); }