示例#1
0
// vaporization is split in two phases - this is phase 1
// PS packs are read into rbuf until a sequence header is found.
// All video packs are unpacketized and the contained video ES
// GOP copied to vibuf. In the same course the private stream 1
// and MPEG audio packs are inspected and the number of packs
// not to be copied are counted. This is to forecast the video
// vaporization factor in case the user specified a PS shrink factor.
// returns GOP length in bytes
int k9vamps::vap_phase1 (void) {
    uchar *ptr, *viptr = vibuf;
    int    seq_length, id, data_length, opt_length, seqhdr;

    for (seq_length = 0;
            !lock (seq_length + SECT_SIZE); seq_length += SECT_SIZE) {
        ptr = rptr + seq_length;
        if (check_pack (ptr)) {
	        ptr += 14;
        	id   = ptr [3];
	} else {
		ptr += 14;
		id   = 0;
	}
	

        // avoid duplicate counts for sequence headers
        if (seq_length)
            total_packs++;

        switch (id) {
        case 0xe0:
            // video
            seqhdr = check_video_packet (ptr);

            if (seq_length) {
                video_packs++;

                if (seqhdr) {
                    sequence_headers++;
                    vilen = viptr - vibuf;

                    return seq_length;
                }
            }

            // copy contained video ES fragment to vibuf
            data_length  = ptr [4] << 8;
            data_length |= ptr [5];
            opt_length   = 3 + ptr [8];
            data_length -= opt_length;

            if ((viptr - vibuf) + data_length > vbuf_size - 3) {
                // reallocate video buffers
                int i = viptr - vibuf;

                // grow by another VBUF_SIZE bytes
                vbuf_size += VBUF_SIZE;
		uchar *tmp;
		tmp =new uchar[vbuf_size];
		memcpy(tmp,vibuf,vbuf_size-VBUF_SIZE);
		delete[] vibuf;
		vibuf = tmp;

//                vibuf      = (uchar*)realloc (vibuf, vbuf_size);
		tmp=new uchar[vbuf_size];
		memcpy(tmp,vobuf,vbuf_size-VBUF_SIZE);
		delete[] vobuf;
		vobuf=tmp;

//                vobuf      = (uchar*)realloc (vobuf, vbuf_size);

                if (vibuf == NULL || vobuf == NULL)
                    fatal ("Reallocation of video buffers failed");

                viptr = vibuf + i;
            }

            //fprintf (stderr, "data_length=%d\n", data_length);
            memcpy (viptr, ptr + 6 + opt_length, data_length);
            viptr += data_length;
            break;

        case 0xbd:
            // private 1: audio/subpicture
            aux_packs++;

            if (!new_private_1_type (ptr))
                skipped_aux_packs++;

            break;

        case 0xc0:
        case 0xc1:
        case 0xc2:
        case 0xc3:
        case 0xc4:
        case 0xc5:
        case 0xc6:
        case 0xc7:
            // MPEG audio
            aux_packs++;

            if (!new_mpeg_audio_id (id))
                skipped_aux_packs++;

            break;

        case 0xbb:
            // system header/private 2: PCI/DSI
            nav_packs++;
            break;

        case 0xbe:
            // padding
            skipped_aux_packs++;
            data_length  = ptr [4] << 8;
            data_length |= ptr [5];

            if (14 + data_length != SECT_SIZE - 6)
                fatal (QString("Bad padding packet length at %1: %2").arg(rtell (ptr)).arg(data_length));

            break;

        default:
//	    fatal("Encountered stream ID %02x at %llu, "
//                   "probably bad MPEG2 program stream", id, rtell (ptr));	
		break;
        }

    }

    eof = 1;

    return seq_length;
}
示例#2
0
int main( int argc, char** argv, char** envp )
{
   std::vector< std::string > all_strings;
   std::vector< steemit::protocol::fixed_string_16 > all_fixed_string_16s;
   std::vector< std::vector< uint32_t > > sim_index;

   std::cout << "setting up LUT's" << std::endl;
   for( int len=0; len<=16; len++ )
   {
      int b_max = 1 << len;
      size_t begin_offset = all_strings.size();

      std::vector< uint32_t > hops;
      for( int b=0; b<b_max; b++ )
      {
         uint32_t ub = uint32_t(b);
         if( popcount(ub) <= 3 )
            hops.push_back( ub );
      }

      for( int b=0; b<b_max; b++ )
      {
         all_strings.emplace_back(len, '\0');
         for( int i=0,m=1; i<len; i++,m+=m )
         {
            all_strings.back()[len-i-1] = ((b&m)==0) ? 'a' : 'b';
         }

         sim_index.emplace_back();
         for( const uint32_t& h : hops )
         {
            sim_index.back().push_back(begin_offset + (b^h));
         }
      }
   }

   /*
   for( size_t i=0; i<all_strings.size(); i++ )
   {
      std::cout << all_strings[i] << std::endl;
      for( const uint32_t& j : sim_index[i] )
         std::cout << "   " << all_strings[j] << std::endl;
   }
   */

   std::cout << "checking conversions, size(), comparison operators" << std::endl;

   for( size_t i=0; i<all_strings.size(); i++ )
   {
      const std::string& s = all_strings[i];
      steemit::protocol::fixed_string_16 fs(s);
      std::string sfs = fs;
      if( s != fs )
      {
         std::cout << "problem on " << s << std::endl;
         ++errors;
      }
      if( fs.size() != s.size() )
      {
         std::cout << "problem on " << s << std::endl;
         ++errors;
      }

      check_variant( s, fs );
      check_pack( s, fs );

      for( const uint32_t& j : sim_index[i] )
      {
         const std::string& t = all_strings[j];
         steemit::protocol::fixed_string_16 ft(t);
         check( s, t, (s< t) == (fs< ft) );
         check( s, t, (s<=t) == (fs<=ft) );
         check( s, t, (s> t) == (fs> ft) );
         check( s, t, (s>=t) == (fs>=ft) );
         check( s, t, (s==t) == (fs==ft) );
         check( s, t, (s!=t) == (fs!=ft) );
      }
   }

   std::cout << "test_fixed_string_16 found " << errors << " errors" << std::endl;

   int result = (errors == 0) ? 0 : 1;

   errors = 0;
   all_strings = std::vector< std::string >();
   std::vector< steemit::protocol::fixed_string_24 > all_fixed_string_24s;
   sim_index = std::vector< std::vector< uint32_t > >();

   std::cout << "setting up LUT's" << std::endl;
   for( int len=0; len<=16; len++ )
   {
      int b_max = 1 << len;
      size_t begin_offset = all_strings.size();

      std::vector< uint32_t > hops;
      for( int b=0; b<b_max; b++ )
      {
         uint32_t ub = uint32_t(b);
         if( popcount(ub) <= 3 )
            hops.push_back( ub );
      }

      for( int b=0; b<b_max; b++ )
      {
         all_strings.emplace_back(len, '\0');
         for( int i=0,m=1; i<len; i++,m+=m )
         {
            all_strings.back()[len-i-1] = ((b&m)==0) ? 'a' : 'b';
         }

         sim_index.emplace_back();
         for( const uint32_t& h : hops )
         {
            sim_index.back().push_back(begin_offset + (b^h));
         }
      }
   }

   std::cout << "checking conversions, size(), comparison operators" << std::endl;

   for( size_t i=0; i<all_strings.size(); i++ )
   {
      const std::string& s = all_strings[i];
      steemit::protocol::fixed_string_24 fs(s);
      std::string sfs = fs;
      if( s != fs )
      {
         std::cout << "problem on " << s << std::endl;
         ++errors;
      }
      if( fs.size() != s.size() )
      {
         std::cout << "problem on " << s << std::endl;
         ++errors;
      }

      check_variant( s, fs );
      check_pack( s, fs );

      for( const uint32_t& j : sim_index[i] )
      {
         const std::string& t = all_strings[j];
         steemit::protocol::fixed_string_24 ft(t);
         check( s, t, (s< t) == (fs< ft) );
         check( s, t, (s<=t) == (fs<=ft) );
         check( s, t, (s> t) == (fs> ft) );
         check( s, t, (s>=t) == (fs>=ft) );
         check( s, t, (s==t) == (fs==ft) );
         check( s, t, (s!=t) == (fs!=ft) );
      }
   }

   std::cout << "test_fixed_string_24 found " << errors << " errors" << std::endl;

   result |= (errors == 0) ? 0 : 1;

   errors = 0;
   all_strings = std::vector< std::string >();
   std::vector< steemit::protocol::fixed_string_32 > all_fixed_string_32s;
   sim_index = std::vector< std::vector< uint32_t > >();

   std::cout << "setting up LUT's" << std::endl;
   for( int len=0; len<=16; len++ )
   {
      int b_max = 1 << len;
      size_t begin_offset = all_strings.size();

      std::vector< uint32_t > hops;
      for( int b=0; b<b_max; b++ )
      {
         uint32_t ub = uint32_t(b);
         if( popcount(ub) <= 3 )
            hops.push_back( ub );
      }

      for( int b=0; b<b_max; b++ )
      {
         all_strings.emplace_back(len, '\0');
         for( int i=0,m=1; i<len; i++,m+=m )
         {
            all_strings.back()[len-i-1] = ((b&m)==0) ? 'a' : 'b';
         }

         sim_index.emplace_back();
         for( const uint32_t& h : hops )
         {
            sim_index.back().push_back(begin_offset + (b^h));
         }
      }
   }

   std::cout << "checking conversions, size(), comparison operators" << std::endl;

   for( size_t i=0; i<all_strings.size(); i++ )
   {
      const std::string& s = all_strings[i];
      steemit::protocol::fixed_string_32 fs(s);
      std::string sfs = fs;
      if( s != fs )
      {
         std::cout << "problem on " << s << std::endl;
         ++errors;
      }
      if( fs.size() != s.size() )
      {
         std::cout << "problem on " << s << std::endl;
         ++errors;
      }

      check_variant( s, fs );
      check_pack( s, fs );

      for( const uint32_t& j : sim_index[i] )
      {
         const std::string& t = all_strings[j];
         steemit::protocol::fixed_string_32 ft(t);
         check( s, t, (s< t) == (fs< ft) );
         check( s, t, (s<=t) == (fs<=ft) );
         check( s, t, (s> t) == (fs> ft) );
         check( s, t, (s>=t) == (fs>=ft) );
         check( s, t, (s==t) == (fs==ft) );
         check( s, t, (s!=t) == (fs!=ft) );
      }
   }

   std::cout << "test_fixed_string_32 found " << errors << " errors" << std::endl;

   result |= (errors == 0) ? 0 : 1;

   return result;
}
示例#3
0
// process beginning of program stream up to
// - but not including - first sequence header
// this PS leader is NOT shrunk since the PS may not
// necessarily begin at a GOP boundary (although it should?)
// nevertheless the unwanted private stream 1 and MPEG audio
// packs are skipped since some players could get confused otherwise
void k9vamps::vap_leader () {
    uchar *ptr;
    int    id, data_length;

    while (!lock (SECT_SIZE)) {
        ptr = rptr;
        if (check_pack (ptr)) {
	        ptr += 14;
        	id   = ptr [3];
	} else {
		ptr +=14;
	        id   = 0;
	}

        switch (id) {
        case 0xe0:
            // video
            if (check_video_packet (ptr))
                // sequence header
                return;

            copy (SECT_SIZE);
	    if (m_dvdbackup)
	       m_dvdbackup->getOutput(k9DVDBackupInterface::VIDEO,0,ptr,SECT_SIZE);

            break;

        case 0xbd:
            // private 1: audio/subpicture
            copy_private_1 (ptr);
            break;

        case 0xc0:
        case 0xc1:
        case 0xc2:
        case 0xc3:
        case 0xc4:
        case 0xc5:
        case 0xc6:
        case 0xc7:
            // MPEG audio
            copy_mpeg_audio (ptr);
            break;

        case 0xbb:
            // system header/private 2: PCI/DSI
            copy (SECT_SIZE);
	    if (m_dvdbackup)
                m_dvdbackup->getOutput(k9DVDBackupInterface::NAV,0,ptr,SECT_SIZE);
            break;

        case 0xbe:
            // padding
            data_length  = ptr [4] << 8;
            data_length |= ptr [5];

            if (14 + data_length != SECT_SIZE - 6)
                fatal (QString("Bad padding packet length at %1: %2").arg(rtell (ptr)).arg(data_length));
  	    //JMP:à vérifier 
  	    skip (SECT_SIZE);

            break;
	   
        default:
	 //   fatal("Encountered stream ID %02x at %llu, "
         //          "probably bad MPEG2 program stream", id, rtell (ptr));
		copy (SECT_SIZE);
        }

        if (wptr == wbuf + WBUF_SIZE)
            flush ();
    }

    eof = 1;
    flush ();

    return;
}
// Test program
int main(void)
{
	// Mapping the sending data address with application's data structure
	struct pack_data* data_send = (struct pack_data*)send_data;
	struct pack_data* data_recv = (struct pack_data*)recv_data;
	enum pack_recv_type_list check_result;

	// Command data
	U8 data[] = {'F'};

	// Initialize the files for communication
	FILE* fd;
	fd = fopen(FILE_FOR_SEND, "w");
	fclose(fd);
	fd = fopen(FILE_FOR_RECV, "w");
	fclose(fd);

	U8 dest_addr;

	// Initialize protocol
	master_init_pack(100, 7000, send_bytes);

	// Bind a callback function to handle the interrupt signal
	// Press key 'Ctrl + C' will send a interrupt signal to the program
	signal(SIGINT, print_pack_count_info);

	// Master send package first
	data_send->cmd = 'E';
	memcpy(data_send->cmd_data, data, sizeof(data));
	master_send_pack(101, sizeof(data)+sizeof(struct pack_data));

	// The loop will be broken when a interrupt signal received
	while (!get_signal_interrupt) {
		dest_addr = get_master_send_addr_last();
		// When ack timeout, master will resend the last package and return
		// the resend times, if the warning value is reached, show messages
		if (master_check_ack_delay() > MASTER_MAX_RETRY_TIMES) {
			printf("The slave %d seems offline.\n", dest_addr);
		}

		// See if a package is arrived
		if (pack_recv()) {
			// Check validity of the received package
			check_result = check_pack();
			if (check_result == PACK_RECV_NEW) {
				// Print the package
				printf("<Master Recv> dest: %d, src: %d, seqno: %d, len: %d, cmd: %c, data: %c\n",
				((struct pack_header*)recv_buf)->dest,
				((struct pack_header*)recv_buf)->src,
				((struct pack_header*)recv_buf)->seqno,
				((struct pack_header*)recv_buf)->len,
				data_recv->cmd,
				data_recv->cmd_data[0]);
			}

			if (dest_addr == 101) {
				dest_addr = 102;
			} else {
				dest_addr = 101;
			}
			// Master send package to salve
			data_send->cmd = 'E';
			memcpy(data_send->cmd_data, data, sizeof(data));
			master_send_pack(dest_addr, sizeof(data)+sizeof(struct pack_data));
		}

		Sleep(2000);
	}

	return 0;
}