分享

PES打包成TS的程序

 昵称12110172 2016-11-15
/***************************************************************************** 
 * bits.h 
 *****************************************************************************/ 
  
 
struct bits_buffer 
{ 
    int     i_size; 
    int     i_data;			//得到最后字节的位置 
    unsigned char i_mask; 
    unsigned char *p_data; 
 
} ; 
 
static inline int bits_initwrite( bits_buffer *p_buffer, int i_size, unsigned char* p_data ) 
{ 
    p_buffer->i_size = i_size; 
    p_buffer->i_data = 0; 
    p_buffer->i_mask = 0x80; 
    p_buffer->p_data = p_data; 
    p_buffer->p_data[0] = 0; 
    if( !p_buffer->p_data ) 
    { 
        if( !( p_buffer->p_data=new unsigned char [i_size] ) ) 
        { 
            return( -1 ); 
        } 
        else 
        { 
            return( 0 ); 
        } 
    } 
    else 
    { 
        return( 0 ); 
    } 
} 
 
static inline void bits_align( bits_buffer *p_buffer ) 
{ 
    if( p_buffer->i_mask != 0x80 && p_buffer->i_data < p_buffer->i_size ) 
    { 
        p_buffer->i_mask = 0x80; 
        p_buffer->i_data++; 
        p_buffer->p_data[p_buffer->i_data] = 0x00; 
    } 
} 
 
static inline void bits_write( bits_buffer *p_buffer, 
                               int i_count, unsigned long  i_bits ) 
{ 
    while( i_count > 0 ) 
    { 
        i_count--; 
 
        if( ( i_bits >> i_count )&0x01 ) 
        { 
            p_buffer->p_data[p_buffer->i_data] |= p_buffer->i_mask; 
        } 
        else 
        { 
            p_buffer->p_data[p_buffer->i_data] &= ~p_buffer->i_mask; 
        } 
        p_buffer->i_mask >>= 1; 
        if( p_buffer->i_mask == 0 ) 
        { 
            p_buffer->i_data++; 
            p_buffer->i_mask = 0x80; 
        } 
    } 
} 
 
static inline void bits_read( bits_buffer *p_buffer, 
                               int i_count, unsigned long  i_bits ) 
{ 
     while( i_count > 0 ) 
    { 
        i_count--; 
 
        if( ( p_buffer->p_data[p_buffer->i_data] >> i_count )&0x01 ) 
        { 
            i_bits |= p_buffer->i_mask; 
        } 
        else 
        { 
            i_bits &= ~p_buffer->i_mask; 
        } 
        p_buffer->i_mask >>= 1; 
        if( p_buffer->i_mask == 0 ) 
        { 
            p_buffer->i_data++; 
            p_buffer->i_mask = 0x80; 
        } 
    } 
} 
 
static inline void bits_Tempread( bits_buffer *p_buffer, 
                               int i_count, unsigned long  i_bits ) 
{ 
	int data=p_buffer->i_data; 
	unsigned char mask=p_buffer->i_mask; 
    while( i_count > 0 ) 
    { 
        i_count--; 
 
        if( ( p_buffer->p_data[p_buffer->i_data] >> i_count )&0x01 ) 
        { 
            i_bits |= p_buffer->i_mask; 
        } 
        else 
        { 
            i_bits &= ~p_buffer->i_mask; 
        } 
        p_buffer->i_mask >>= 1; 
        if( p_buffer->i_mask == 0 ) 
        { 
            p_buffer->i_data++; 
            p_buffer->i_mask = 0x80; 
        } 
    } 
	p_buffer->i_data=data; 
	p_buffer->i_mask=mask; 
} 
 
static	inline next_start_code(bits_buffer *p_buffer) 
{	 
	bits_align(p_buffer); 
	/* Check if we are at the start code.   
	If not there is zero byte stuffing */ 
	 
	/* check starting code or skip zero byte stuffing */ 
	long result; 
	bits_Tempread(p_buffer,24,result); 
	while(!(result==0x000001))  
	{ 
		bits_read(p_buffer,1,result); 
		bits_Tempread(p_buffer,24,result); 
	} 
	 
} 
 

DefPara.h
#pragma once 
#include <stdlib.h>                            /* calloc(), malloc(), free() */ 
#include <string.h> 
#define PES_PROGRAM_STREAM_MAP          0xbc 
#define PES_PRIVATE_STREAM_1            0xbd 
#define PES_PADDING                     0xbe 
#define PES_PRIVATE_STREAM_2            0xbf 
#define PES_ECM                         0xb0 
#define PES_EMM                         0xb1 
#define PES_PROGRAM_STREAM_DIRECTORY    0xff 
#define PES_DSMCC_STREAM                0xf2 
#define PES_ITU_T_H222_1_TYPE_E_STREAM  0xf8 
#define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) ) 
 
#define UNKNOWN_ES      0x00 
#define VIDEO_ES        0x01 
#define AUDIO_ES        0x02 
#define SPU_ES          0x03 
#define NAV_ES          0x04 
 
 
typedef DWORD					mtime; 
typedef unsigned int			uint32; 
typedef unsigned char			uchar; 
 
/* for mux */ 
typedef struct buffer_t 
{ 
	uchar					*p_buffer; 
    int						i_size; 
    DWORD					i_dts; 
    DWORD					i_pts; 
	buffer_t*				p_next; 
} 
PES_PARA,ES_PARA,TS_PARA; 
 
typedef struct TSParamer 
{ 
    int					i_pid; 
    int					i_stream_type; 
    int					i_stream_id; 
    mtime				i_pes_dts; 
    mtime				i_pes_length; 
} TSPARAMER; 
 
// ESToTS.h: interface for the ESToTS class. 
// 
////////////////////////////////////////////////////////////////////// 

 
#pragma once 
#include "bits.h" 
#include "DefPara.h" 
 
class ESToTS   
{ 
public: 
	bool m_bFileOpen; 
	HRESULT hr; 
	HRESULT OpenFile(FILE*); 
	HRESULT WriteFile(TS_PARA *TsBuffer); 
	HRESULT PESToTS(PES_PARA *p_pes,TSPARAMER *p_stream); 
	HRESULT EstoPES( ES_PARA *p_es,				//ES Stream Data 
					int i_stream_id,              //Allocter the strean ID 
					int b_mpeg2 ); 
	HRESULT GetES(uchar* buffer, int length); 
	int InitPESHeader(unsigned char *p_hdr, 
					DWORD i_pts,			//PTS 
					DWORD i_dts,			//DTS 
                    int   i_es_size,		//ES Streamdata length 
					int   i_stream_id,		//Strean ID 
					int   i_private_id,		//Addtion parater data 
                    int   b_mpeg2 ); 
	ESToTS(); 
	virtual ~ESToTS(); 
	FILE *fd; 
 
}; 
 
  1. // ESToTS.cpp: implementation of the ESToTS class.   
  2. //   
  3. //////////////////////////////////////////////////////////////////////   
  4.    
  5. #include "stdafx.h"   
  6. #include "ParkertTS.h"   
  7. #include "ESToTS.h"   
  8. #include <io.h>   
  9. #include <fcntl.h>   
  10. #include <stdio.h>   
  11. #include <stdlib.h>   
  12. #include <memory.h>    
  13. #include "string.h"   
  14.    
  15.    
  16. #ifdef _DEBUG   
  17. #undef THIS_FILE   
  18. static char THIS_FILE[]=__FILE__;   
  19. #define new DEBUG_NEW   
  20. #endif   
  21.    
  22. #define PES_PAYLOAD_SIZE_MAX 2048   
  23.    
  24. //////////////////////////////////////////////////////////////////////   
  25. // Construction/Destruction   
  26. //////////////////////////////////////////////////////////////////////   
  27.    
  28. ESToTS::ESToTS(): hr(S_OK),m_bFileOpen(false)   
  29. {   
  30.    
  31. }   
  32.    
  33. ESToTS::~ESToTS()   
  34. {   
  35.    
  36. }   
  37.    
  38. int ESToTS::InitPESHeader(unsigned char *p_hdr,   
  39.                                 DWORD i_pts,            //PTS   
  40.                                 DWORD i_dts,            //DTS   
  41.                                 int   i_es_size,        //ES Streamdata length   
  42.                                 int   i_stream_id,      //Strean ID   
  43.                                 int   i_private_id,     //Addtion parater data   
  44.                                 int   b_mpeg2 )   
  45. {   
  46.     bits_buffer bits;   
  47.     int     i_extra = 0;   
  48.    
  49.     /* For PES_PRIVATE_STREAM_1 there is an extra header after the pes header */   
  50.     /* i_private_id != -1 because TS use 0xbd without private_id */   
  51.     if( i_stream_id == PES_PRIVATE_STREAM_1 && i_private_id != -1 )   
  52.     {   
  53.         i_extra = 1;   
  54.         if( ( i_private_id & 0xf0 ) == 0x80 )   
  55.         {   
  56.             i_extra += 3;   
  57.         }   
  58.     }   
  59.    
  60.    
  61.     bits_initwrite( &bits, 30, p_hdr );   
  62.    
  63.     /* add start code */   
  64.     bits_write( &bits, 24, 0x01 );   
  65.     bits_write( &bits, 8, i_stream_id );   
  66.     switch( i_stream_id )   
  67.     {   
  68.         case PES_PROGRAM_STREAM_MAP:   
  69.         case PES_PADDING:   
  70.         case PES_PRIVATE_STREAM_2:   
  71.         case PES_ECM:   
  72.         case PES_EMM:   
  73.         case PES_PROGRAM_STREAM_DIRECTORY:   
  74.         case PES_DSMCC_STREAM:   
  75.         case PES_ITU_T_H222_1_TYPE_E_STREAM:   
  76.             /* add pes data size  */   
  77.             bits_write( &bits, 16, i_es_size );   
  78.             bits_align( &bits );   
  79.             return( bits.i_data );   
  80.    
  81.         default:   
  82.             /* arg, a little more difficult */   
  83.             if( b_mpeg2 )   
  84.             {   
  85.                 int i_pts_dts;   
  86.    
  87.                 if( i_pts > 0 && i_dts > 0 )   
  88.                 {   
  89.                     bits_write( &bits, 16, i_es_size + i_extra+ 13 );   
  90.                     i_pts_dts = 0x03;   
  91.                 }   
  92.                 else if( i_pts > 0 )   
  93.                 {   
  94.                     bits_write( &bits, 16, i_es_size  + i_extra + 8 );   
  95.                     i_pts_dts = 0x02;   
  96.                 }   
  97.                 else   
  98.                 {   
  99.                     bits_write( &bits, 16, i_es_size  + i_extra + 3 );   
  100.                     i_pts_dts = 0x00;   
  101.                 }   
  102.    
  103.                 bits_write( &bits, 2, 0x02 ); // mpeg2 id   
  104.                 bits_write( &bits, 2, 0x00 ); // pes scrambling control   
  105.                 bits_write( &bits, 1, 0x00 ); // pes priority   
  106.                 bits_write( &bits, 1, 0x00 ); // data alignement indicator   
  107.                 bits_write( &bits, 1, 0x00 ); // copyright   
  108.                 bits_write( &bits, 1, 0x00 ); // original or copy   
  109.    
  110.                 bits_write( &bits, 2, i_pts_dts ); // pts_dts flags   
  111.                 bits_write( &bits, 1, 0x00 ); // escr flags   
  112.                 bits_write( &bits, 1, 0x00 ); // es rate flag   
  113.                 bits_write( &bits, 1, 0x00 ); // dsm trick mode flag   
  114.                 bits_write( &bits, 1, 0x00 ); // additional copy info flag   
  115.                 bits_write( &bits, 1, 0x00 ); // pes crc flag   
  116.                 bits_write( &bits, 1, 0x00 ); // pes extention flags   
  117.                 if( i_pts_dts == 0x03 )   
  118.                 {   
  119.                     bits_write( &bits, 8, 0x0a ); // header size -> pts and dts   
  120.                 }   
  121.                 else if( i_pts_dts == 0x02 )   
  122.                 {   
  123.                     bits_write( &bits, 8, 0x05 ); // header size -> pts   
  124.                 }   
  125.                 else   
  126.                 {   
  127.                     bits_write( &bits, 8, 0x00 ); // header size -> 0   
  128.                 }   
  129.    
  130.                 /* write pts */   
  131.                 if( i_pts_dts & 0x02 )   
  132.                 {   
  133.                     bits_write( &bits, 4, i_pts_dts ); // '0010' or '0011'   
  134.                     bits_write( &bits, 3, i_pts >> 30 );   
  135.                     bits_write( &bits, 1, 0x01 ); // marker   
  136.                     bits_write( &bits, 15, i_pts >> 15 );   
  137.                     bits_write( &bits, 1, 0x01 ); // marker   
  138.                     bits_write( &bits, 15, i_pts );   
  139.                     bits_write( &bits, 1, 0x01 ); // marker   
  140.                 }   
  141.                 /* write i_dts */   
  142.                 if( i_pts_dts & 0x01 )   
  143.                 {   
  144.                     bits_write( &bits, 4, 0x01 ); // '0001'   
  145.                     bits_write( &bits, 3, i_dts >> 30 );   
  146.                     bits_write( &bits, 1, 0x01 ); // marker   
  147.                     bits_write( &bits, 15, i_dts >> 15 );   
  148.                     bits_write( &bits, 1, 0x01 ); // marker   
  149.                     bits_write( &bits, 15, i_dts );   
  150.                     bits_write( &bits, 1, 0x01 ); // marker   
  151.                 }   
  152.             }   
  153.             else /* MPEG1 */   
  154.             {   
  155.                 int i_pts_dts;   
  156.    
  157.                 if( i_pts > 0 && i_dts > 0 )   
  158.                 {   
  159.                     bits_write( &bits, 16, i_es_size + i_extra + 10 /* + stuffing */ );   
  160.                     i_pts_dts = 0x03;   
  161.                 }   
  162.                 else if( i_pts > 0 )   
  163.                 {   
  164.                     bits_write( &bits, 16, i_es_size + i_extra + 5 /* + stuffing */ );   
  165.                     i_pts_dts = 0x02;   
  166.                 }   
  167.                 else   
  168.                 {   
  169.                     bits_write( &bits, 16, i_es_size + i_extra + 1 /* + stuffing */);   
  170.                     i_pts_dts = 0x00;   
  171.                 }   
  172.    
  173.                 /* FIXME: Now should be stuffing */   
  174.    
  175.                 /* No STD_buffer_scale and STD_buffer_size */   
  176.    
  177.                 /* write pts */   
  178.                 if( i_pts_dts & 0x02 )   
  179.                 {   
  180.                     bits_write( &bits, 4, i_pts_dts ); // '0010' or '0011'   
  181.                     bits_write( &bits, 3, i_pts >> 30 );   
  182.                     bits_write( &bits, 1, 0x01 ); // marker   
  183.                     bits_write( &bits, 15, i_pts >> 15 );   
  184.                     bits_write( &bits, 1, 0x01 ); // marker   
  185.                     bits_write( &bits, 15, i_pts );   
  186.                     bits_write( &bits, 1, 0x01 ); // marker   
  187.                 }   
  188.                 /* write i_dts */   
  189.                 if( i_pts_dts & 0x01 )   
  190.                 {   
  191.                     bits_write( &bits, 4, 0x01 ); // '0001'   
  192.                     bits_write( &bits, 3, i_dts >> 30 );   
  193.                     bits_write( &bits, 1, 0x01 ); // marker   
  194.                     bits_write( &bits, 15, i_dts >> 15 );   
  195.                     bits_write( &bits, 1, 0x01 ); // marker   
  196.                     bits_write( &bits, 15, i_dts );   
  197.                     bits_write( &bits, 1, 0x01 ); // marker   
  198.                 }   
  199.                 if( !i_pts_dts )   
  200.                 {   
  201.                     bits_write( &bits, 8, 0x0F );   
  202.                 }   
  203.    
  204.             }   
  205.    
  206.             /* now should be stuffing */   
  207.             /* and then pes data */   
  208.    
  209.             bits_align( &bits );   
  210.             if( i_stream_id == PES_PRIVATE_STREAM_1 && i_private_id != -1 )   
  211.             {   
  212.                 bits_write( &bits, 8, i_private_id );   
  213.                 if( ( i_private_id&0xf0 ) == 0x80 )   
  214.                 {   
  215.                     bits_write( &bits, 24, 0 ); // ac3   
  216.                 }   
  217.             }   
  218.             bits_align( &bits );   
  219.             return( bits.i_data );   
  220.     }   
  221.    
  222. }   
  223.    
  224.    
  225. HRESULT ESToTS::GetES(uchar* buffer, int length)   
  226. {   
  227.     int                     i_stream_id=23;   
  228.     int                     b_video =VIDEO_ES;   
  229.    
  230.     ES_PARA                 *m_es;   
  231.     //(m_es,0,sizeof(ES_PARA));   
  232.     m_es = (ES_PARA *)malloc( sizeof(ES_PARA) );   
  233.    
  234.    
  235.     DWORD                   i_pts=0,    i_dts=0;   
  236.     m_es->i_dts              =0;   
  237.     m_es->i_pts              =0;   
  238.     m_es->i_size         =length;   
  239.     m_es->p_buffer           =buffer;   
  240.     m_es->p_next         =NULL;   
  241.     hr=EstoPES(m_es,i_stream_id,1);   
  242.     if(FAILED(hr))   
  243.         AfxMessageBox("EstoPES Failed");   
  244.     return hr;   
  245. }   
  246.    
  247. HRESULT ESToTS::EstoPES(ES_PARA *p_es,              //ES Stream Data   
  248.                         int i_stream_id,              //Allocter the strean ID   
  249.                         int b_mpeg2 )   
  250. {   
  251.     mtime           i_pts, i_dts, i_length;   
  252.     PES_PARA        *p_pes;   
  253.     uchar           *p_data;   
  254.     int             i_size;   
  255.     int             i_private_id = -1;   
  256.    
  257.     unsigned char   header[30];     // PES header + extra < 30 (more like 17)   
  258.     int             i_pes_payload;   
  259.     int             i_pes_header;   
  260.     int             i_pes_count = 1;   
  261.     p_pes = (ES_PARA *)malloc( sizeof(ES_PARA) );   
  262.    
  263.     /* HACK for private stream 1 in ps */   
  264.     if( ( i_stream_id >> 8 ) == PES_PRIVATE_STREAM_1 )   
  265.     {   
  266.         i_private_id = i_stream_id & 0xff;   
  267.         i_stream_id  = PES_PRIVATE_STREAM_1;   
  268.     }   
  269.    
  270.     i_pts = p_es->i_pts <= 0 ? 0 : p_es->i_pts * 9 / 100; // 90000 units clock   
  271.     i_dts = p_es->i_dts <= 0 ? 0 : p_es->i_dts * 9 / 100; // 90000 units clock   
  272.    
  273.     i_size = p_es->i_size;   
  274.     p_data = p_es->p_buffer;   
  275.     do   
  276.     {   
  277.         i_pes_payload = __MIN( i_size, PES_PAYLOAD_SIZE_MAX );   
  278.         //得到头文件的最后一字的位置   
  279.         i_pes_header  = InitPESHeader( header, i_pts, i_dts, i_pes_payload,   
  280.                                    i_stream_id, i_private_id, b_mpeg2 );   
  281.    
  282.         // only first PES has a dts/pts   
  283.         i_dts = 0;   
  284.         i_pts = 0;   
  285.            
  286.         //把PES头写入PES域   
  287.    
  288.         uchar*  buffer=new uchar[i_pes_payload+i_pes_header];   
  289.         memset(buffer,0,i_pes_payload+i_pes_header);   
  290.    
  291.         memcpy(buffer,header,i_pes_header);   
  292. //      for(int i =0;i<i_pes_header;i++)   
  293. //          *buffer++=header[i];   
  294. //      memcpy(p_pes->p_buffer,header,i_pes_header);   
  295.         //把ES数据写入PES域   
  296.        
  297. //      for(i=0;i<i_pes_payload;i++)   
  298. //          *buffer++=*p_data++;   
  299.                
  300.         memcpy(buffer+i_pes_header,p_data,i_pes_payload);   
  301. //      memcpy(p_pes->p_buffer+i_pes_header,p_data,i_pes_payload);   
  302.    
  303.         //把PES数据写入TS文件中   
  304.         TSPARAMER *m_tspara;   
  305.         m_tspara = (TSPARAMER *)malloc( sizeof(TSPARAMER) );   
  306.         m_tspara->i_pid=i_stream_id;   
  307.         m_tspara->i_stream_id=i_stream_id;   
  308.         m_tspara->i_pes_length=p_pes->i_size=i_pes_payload;   
  309.         m_tspara->i_stream_type=VIDEO_ES;   
  310.         p_pes->p_buffer=buffer;   
  311.        
  312.         hr=PESToTS(p_pes,m_tspara);   
  313.         if(FAILED(hr))   
  314.             AfxMessageBox("Failed Copy PES to Ts");   
  315.         i_size-=i_pes_payload;   
  316.     }   
  317.     while(i_size==0);     
  318.    
  319.     return hr;   
  320.    
  321. }   
  322.    
  323. HRESULT ESToTS::PESToTS(PES_PARA *p_pes,TSPARAMER *p_stream)   
  324. {   
  325.     uchar   *p_data;   
  326.     int     i_size;   
  327.     int     b_new_pes;   
  328.    
  329.     /* get PES total size */   
  330.     i_size = p_pes->i_size;   
  331.     p_data = p_pes->p_buffer;   
  332.    
  333.     b_new_pes = 1;   
  334.    
  335.     for( ;; )   
  336.     {   
  337.         int           b_adaptation_field;   
  338.         int           i_copy;   
  339.         TS_PARA         *p_ts;   
  340.         int           i_continuity_counter=0;   
  341.         p_ts=(TS_PARA*)malloc(sizeof(TS_PARA));   
  342.            
  343.         i_copy    = __MIN( i_size, 184 );   
  344.         b_adaptation_field = i_size < 184 ? 1 : 0;   
  345.    
  346.         uchar buffer[188];   
  347.         buffer[0] = 0x47;   
  348.         buffer[1] = ( b_new_pes ? 0x40 : 0x00 )|  ( ( p_stream->i_pid >> 8 )&0x1f );   
  349.         buffer[2] = p_stream->i_pid & 0xff;   
  350.         buffer[3] = ( b_adaptation_field ? 0x30 : 0x10 )| i_continuity_counter;   
  351.    
  352.            
  353.         //写入TS头标志   
  354. //        p_ts->p_buffer[0] = 0x47;   
  355. //        p_ts->p_buffer[1] = ( b_new_pes ? 0x40 : 0x00 )|  ( ( p_stream->i_pid >> 8 )&0x1f );   
  356. //        p_ts->p_buffer[2] = p_stream->i_pid & 0xff;   
  357. //        p_ts->p_buffer[3] = ( b_adaptation_field ? 0x30 : 0x10 )| i_continuity_counter;   
  358.    
  359.         b_new_pes = 0;   
  360.         i_continuity_counter = (i_continuity_counter+1)%16;   
  361.    
  362.         if( b_adaptation_field )   
  363.         {   
  364.             int i_stuffing = 184 - i_copy;   
  365.             int i;   
  366.    
  367. //            p_ts->p_buffer[4] = i_stuffing - 1;   
  368.             buffer[4] = i_stuffing - 1;   
  369.             if( i_stuffing > 1 )   
  370.             {   
  371. //                p_ts->p_buffer[5] = 0x00;   
  372.                 buffer[5]=0x00;   
  373.                 for( i = 6; i < 6 + i_stuffing - 2; i++ )   
  374.                 {   
  375.                     buffer[i]=0xff;   
  376. //                    p_ts->p_buffer[i] = 0xff;   
  377.                 }   
  378.             }   
  379.         }   
  380.         /* copy payload */   
  381. //      memcpy( p_ts->p_buffer+(188 - i_copy), p_data, i_copy );   
  382.         memcpy( buffer+(188 - i_copy), p_data, i_copy );   
  383.         p_ts->p_buffer=buffer;   
  384.         hr=WriteFile(p_ts);   
  385.         if(FAILED(hr))   
  386.         {   
  387.             AfxMessageBox("WriteFile Fasiled");   
  388.             return hr;   
  389.         }   
  390.    
  391.    
  392.         p_data += i_copy;   
  393.         i_size -= i_copy;   
  394.    
  395.         if( i_size <= 0 )   
  396.         {   
  397.            break;   
  398.         }   
  399.     }   
  400.     return hr;   
  401. }   
  402.    
  403. HRESULT ESToTS::WriteFile(TS_PARA *TsBuffer)   
  404. {   
  405.     if(!m_bFileOpen)   
  406.     {   
  407.         if (!(fd = fopen("D:\\zzl.ts","w")))   
  408.         {   
  409.              AfxMessageBox("Couldn't open parameter file");   
  410.              return 0;   
  411.         }      
  412.         m_bFileOpen=true;   
  413.     }   
  414.     fwrite( TsBuffer->p_buffer, sizeofchar ), 188, fd );   
  415. }   
  416.    
  417. HRESULT ESToTS::OpenFile( FILE * fd)   
  418. {   
  419.     int  fh, count, total = 0;   
  420.     char buf[2028];   
  421.     if( (fh = _open( "c:\\test1.m2v", _O_RDONLY )) == - 1 )   
  422.        {   
  423.         AfxMessageBox( "Open failed");   
  424.         exit( 1 );   
  425.        }   
  426.     /* Cycle until end of file reached: */   
  427.     do   
  428.     {   
  429.       /* Attempt to read in 10 bytes: */   
  430.       if( (count = _read( fh, buf, 2028 )) == -1 )   
  431.       {   
  432.          perror( "Read error" );   
  433.          break;   
  434.       }   
  435.       /* Total actual bytes read */   
  436.       hr=GetES((uchar *)buf,2028);   
  437.       if(FAILED (hr))   
  438.           AfxMessageBox("GetES Failed");   
  439.    
  440.       total += count;   
  441.     }   
  442.     while( _eof( fh ) );   
  443.     _close( fh );   
  444.     return hr;   
  445. }   

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多