#define ES_DEFAULT_VIDEO_PTS_OFFSET 20000000
#define ES_DEFAULT_NUMBER_OF_FEED 2000
-unsigned char sps[100];
-unsigned char pps[100];
-unsigned char tmp_buf[1000000];
-static int sps_len, pps_len;
-
#ifdef PACKAGE
#undef PACKAGE
#endif
static int app_pause(void *data);
static int app_terminate(void *data);
+typedef enum {
+ NAL_SLICE_NO_PARTITIONING = 1,
+ NAL_SLICE_PART_A,
+ NAL_SLICE_PART_B,
+ NAL_SLICE_PART_C,
+ NAL_SLICE_IDR,
+ NAL_SEI,
+ NAL_SEQUENCE_PARAMETER_SET,
+ NAL_PICTURE_PARAMETER_SET,
+ NAL_PICTURE_DELIMITER,
+ NAL_END_OF_SEQUENCE,
+ NAL_END_OF_STREAM,
+ NAL_FILLER_DATA,
+ NAL_PREFIX_SVC = 14
+} nal_unit_type;
+
struct appcore_ops ops = {
.create = app_create,
.terminate = app_terminate,
int read_size = 1;
unsigned char buffer[1000000];
unsigned char val, zero_count, i;
- int nal_unit_type = 0;
- int init;
+ int init = 0;
+ int type = 0;
- zero_count = 0;
if (feof(fd))
return -1;
- result = fread(buffer, 1, read_size, fd);
-
- if (result != read_size)
- return -1;
-
- val = buffer[0];
- while (1) {
- if ((zero_count == 2 || zero_count == 3) && val == 1)
- break;
- zero_count++;
+ do {
+ zero_count = 0;
result = fread(buffer, 1, read_size, fd);
if (result != read_size)
- break;
- val = buffer[0];
- }
- nal[nal_length++] = 0;
- nal[nal_length++] = 0;
- nal[nal_length++] = 0;
- nal[nal_length++] = 1;
- zero_count = 0;
- init = 1;
- while (1) {
- if (feof(fd))
return -1;
- result = fread(buffer, 1, read_size, fd);
- if (result != read_size) {
- if (init == 1)
- return -1;
- break;
- }
val = buffer[0];
+ nal[nal_length++] = val;
+ while (1) {
+ if ((zero_count == 2 || zero_count == 3) && val == 1)
+ break;
+ zero_count++;
+ result = fread(buffer, 1, read_size, fd);
- if (init) {
- nal_unit_type = val & 0xf;
- init = 0;
+ if (result != read_size)
+ break;
+ val = buffer[0];
+ nal[nal_length++] = val;
}
- if (!val) {
- zero_count++;
- } else {
- if ((zero_count == 2 || zero_count == 3 || zero_count == 4) && (val == 1)) {
+
+ zero_count = 0;
+ init = 1;
+
+ while (1) {
+ if (feof(fd))
+ return -1;
+
+ result = fread(buffer, 1, read_size, fd);
+ if (result != read_size) {
break;
+ }
+
+ val = buffer[0];
+
+ if (init) {
+ type = val & 0x1F;
+ init = 0;
+ }
+
+ if (!val) {
+ zero_count++;
} else {
- for (i = 0; i < zero_count; i++)
- nal[nal_length++] = 0;
- nal[nal_length++] = val;
- zero_count = 0;
+ if ((zero_count == 2 || zero_count == 3 || zero_count == 4)
+ && (val == 1)) {
+ break;
+ } else {
+ for (i = 0; i < zero_count; i++)
+ nal[nal_length++] = 0;
+ nal[nal_length++] = val;
+ zero_count = 0;
+ }
}
}
- }
- if (fseek(fd, -(zero_count + 1), SEEK_CUR) < 0) {
- LOGE("failed fseek");
- return -1;
- }
+ fseek(fd, -(zero_count + 1), SEEK_CUR);
+ } while (type == NAL_SEI ||
+ type == NAL_SEQUENCE_PARAMETER_SET ||
+ type == NAL_PICTURE_PARAMETER_SET ||
+ type == NAL_PICTURE_DELIMITER);
- if (nal_unit_type == 0x7) {
- sps_len = nal_length;
- memcpy(sps, nal, nal_length);
- return 0;
- } else if (nal_unit_type == 0x8) {
- pps_len = nal_length;
- memcpy(pps, nal, nal_length);
- return 0;
- } else if (nal_unit_type == 0x5) {
- memcpy(tmp_buf, nal, nal_length);
- memcpy(nal, sps, sps_len);
- memcpy(nal + sps_len, pps, pps_len);
- memcpy(nal + sps_len + pps_len, tmp_buf, nal_length);
- nal_length += sps_len + pps_len;
- }
return nal_length;
}