00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "contributors.h"
00016
00017 #include "global.h"
00018 #include "enc_statistics.h"
00019
00020 #include "rtp.h"
00021 #include "annexb.h"
00022 #include "parset.h"
00023 #include "mbuffer.h"
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 void error(char *text, int code)
00038 {
00039 fprintf(stderr, "%s\n", text);
00040 flush_dpb(p_Enc->p_Img, p_Enc->p_Inp, &p_Enc->p_Inp->output);
00041 exit(code);
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051 int write_PPS(ImageParameters *p_Img, InputParameters *p_Inp, int len, int PPS_id)
00052 {
00053 NALU_t *nalu;
00054 nalu = NULL;
00055 nalu = GeneratePic_parameter_set_NALU (p_Img, p_Inp, PPS_id);
00056 len += p_Img->WriteNALU (p_Img, nalu);
00057 FreeNALU (nalu);
00058
00059 return len;
00060 }
00061
00062
00063
00064
00065
00066
00067
00068
00069 int start_sequence(ImageParameters *p_Img, InputParameters *p_Inp)
00070 {
00071 int i,len=0, total_pps = (p_Inp->GenerateMultiplePPS) ? 3 : 1;
00072 NALU_t *nalu;
00073
00074 switch(p_Inp->of_mode)
00075 {
00076 case PAR_OF_ANNEXB:
00077 OpenAnnexbFile (p_Img, p_Inp->outfile);
00078 p_Img->WriteNALU = WriteAnnexbNALU;
00079 break;
00080 case PAR_OF_RTP:
00081 OpenRTPFile (p_Img, p_Inp->outfile);
00082 p_Img->WriteNALU = WriteRTPNALU;
00083 break;
00084 default:
00085 snprintf(errortext, ET_SIZE, "Output File Mode %d not supported", p_Inp->of_mode);
00086 error(errortext,1);
00087 }
00088
00089
00090 if ( p_Inp->SendAUD )
00091 {
00092 len += Write_AUD_NALU(p_Img);
00093 }
00094
00095
00096
00097
00098
00099
00100 nalu = NULL;
00101 nalu = GenerateSeq_parameter_set_NALU (p_Img);
00102 len += p_Img->WriteNALU (p_Img, nalu);
00103 FreeNALU (nalu);
00104
00105
00106 for (i=0;i<total_pps;i++)
00107 {
00108 len = write_PPS(p_Img, p_Inp, len, i);
00109 }
00110
00111 if (p_Inp->GenerateSEIMessage)
00112 {
00113 nalu = NULL;
00114 nalu = GenerateSEImessage_NALU(p_Inp);
00115 len += p_Img->WriteNALU (p_Img, nalu);
00116 FreeNALU (nalu);
00117 }
00118
00119 p_Img->p_Stats->bit_ctr_parametersets_n = len;
00120 return 0;
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130 int rewrite_paramsets(ImageParameters *p_Img, InputParameters *p_Inp)
00131 {
00132 int i,len=0, total_pps = (p_Inp->GenerateMultiplePPS) ? 3 : 1;
00133 NALU_t *nalu;
00134
00135
00136 if ( p_Inp->SendAUD )
00137 {
00138 len += Write_AUD_NALU(p_Img);
00139 }
00140
00141
00142
00143
00144
00145
00146 nalu = NULL;
00147 nalu = GenerateSeq_parameter_set_NALU (p_Img);
00148 len += p_Img->WriteNALU (p_Img, nalu);
00149 FreeNALU (nalu);
00150
00151
00152 for (i=0;i<total_pps;i++)
00153 {
00154 len = write_PPS(p_Img, p_Inp, len, i);
00155 }
00156
00157 if (p_Inp->GenerateSEIMessage)
00158 {
00159 nalu = NULL;
00160 nalu = GenerateSEImessage_NALU(p_Inp);
00161 len += p_Img->WriteNALU (p_Img, nalu);
00162 FreeNALU (nalu);
00163 }
00164
00165 p_Img->p_Stats->bit_ctr_parametersets_n = len;
00166 return 0;
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176 int terminate_sequence(ImageParameters *p_Img, InputParameters *p_Inp)
00177 {
00178
00179
00180
00181
00182
00183 switch(p_Inp->of_mode)
00184 {
00185 case PAR_OF_ANNEXB:
00186 CloseAnnexbFile(p_Img);
00187 break;
00188 case PAR_OF_RTP:
00189 CloseRTPFile(p_Img);
00190 return 0;
00191 default:
00192 snprintf(errortext, ET_SIZE, "Output File Mode %d not supported", p_Inp->of_mode);
00193 error(errortext,1);
00194 }
00195 return 1;
00196 }
00197