[asterisk-commits] rizzo: branch rizzo/video_v2 r85282 - /team/rizzo/video_v2/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Oct 10 09:51:02 CDT 2007
Author: rizzo
Date: Wed Oct 10 09:51:01 2007
New Revision: 85282
URL: http://svn.digium.com/view/asterisk?view=rev&rev=85282
Log:
more h261 split...
Modified:
team/rizzo/video_v2/channels/console_video.c
Modified: team/rizzo/video_v2/channels/console_video.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/video_v2/channels/console_video.c?view=diff&rev=85282&r1=85281&r2=85282
==============================================================================
--- team/rizzo/video_v2/channels/console_video.c (original)
+++ team/rizzo/video_v2/channels/console_video.c Wed Oct 10 09:51:01 2007
@@ -712,6 +712,7 @@
//ast_log(LOG_WARNING, "search at %d of %d/%d\n", i, start, len);
for (; i < len ; i++) {
uint8_t x, rpos, lpos;
+ int rpos_i; /* index corresponding to rpos */
if (d[i] != 0) /* cannot be in a GBSC */
continue;
if (i > len - 1)
@@ -724,7 +725,7 @@
* see if we have enough 0 on the left.
* We are guaranteed to end before rpos == 0
*/
- for (rpos = 0x80; rpos; rpos >>= 1)
+ for (rpos = 0x80, rpos_i = 8; rpos; rpos >>= 1, rpos_i--)
if (x & rpos) /* found the '1' bit in GBSC */
break;
x = d[i-1]; /* now look behind */
@@ -739,8 +740,8 @@
if (rpos == 0x80) { /* lucky case */
i = i - 1;
} else { /* XXX to be completed */
- ast_log(LOG_WARNING, "unaligned GBSC 0x%x\n",
- rpos);
+ ast_log(LOG_WARNING, "unaligned GBSC 0x%x %d\n",
+ rpos, rpos_i);
}
break;
}
@@ -831,15 +832,22 @@
const int pheader_len = 4;
uint8_t h261_hdr[4];
uint8_t *h = h261_hdr; /* shorthand */
-
-#define H261_MIN_LEN 4
+ int sbit = 0, ebit = 0;
+
+#define H261_MIN_LEN 10
if (len < H261_MIN_LEN) /* unreasonably small */
return NULL;
bzero(h261_hdr, sizeof(h261_hdr));
- h[0] = 0x01; /* sbit = ebit = 0, i=0, v=1, all others 0 */
-
- for (i = H261_MIN_LEN, start = 0; start < len; start = i, i += 3) {
+
+ /* This is the same code we have in h263, but the maker there is longer.
+ * We start a few bytes within the bitstream to avoid hitting the marker
+ * twice. We stop at len-1 because when there are bits to ignore we move
+ * back the 'start' pointer by 1, and this would cause us to enter the loop
+ * one more time.
+ */
+ for (i = H261_MIN_LEN, start = 0; start < len - 1; start = i, i += 4) {
+ int found = 0, found_ebit = 0; /* last GBSC position found */
ast_log(LOG_WARNING, "search at %d of %d/%d\n", i, start, len);
for (; i < len ; i++) {
uint8_t x, rpos, lpos;
@@ -855,7 +863,7 @@
* see if we have enough 0 on the left.
* We are guaranteed to end before rpos == 0
*/
- for (rpos = 0x80; rpos; rpos >>= 1)
+ for (rpos = 0x80, ebit = 7; rpos; ebit--, rpos >>= 1)
if (x & rpos) /* found the '1' bit in GBSC */
break;
x = d[i-1]; /* now look behind */
@@ -865,16 +873,23 @@
if (lpos) /* as i said... */
continue;
/* now we have a GBSC starting somewhere in d[i-1],
- * but it might be not byte-aligned
+ * but it might be not byte-aligned. Just remember it.
*/
- if (rpos == 0x80) { /* lucky case */
- i = i - 1;
- } else { /* XXX to be completed */
- ast_log(LOG_WARNING, "unaligned GBSC 0x%x\n",
- rpos);
- }
- break;
+ if (i > out->mtu) /* too large, stop now */
+ break;
+ found_ebit = ebit;
+ found = i;
+ i += 4; /* continue forward */
}
+ if (i > len) { /* trim if we went too forward */
+ i = len;
+ ebit = 0; /* hopefully... should ask the bitstream ? */
+ }
+ if (i > out->mtu && found) { /* hope the previous one is still ok */
+ i = found;
+ ebit = found_ebit;
+ }
+ ast_log(LOG_WARNING, "found %d of %d/%d\n", i - start, start, len);
/* This frame is up to offset i (not inclusive).
* We do not split it yet even if larger than MTU.
*/
@@ -883,10 +898,14 @@
if (!f)
break;
- bcopy(h, f->data, 4); /* copy the h263 header */
- /* XXX to do: if not aligned, fix sbit and ebit,
- * then move i back by 1 for the next frame
- */
+ /* recompute header with I=0, V=1 */
+ h[0] = ( (sbit & 7) << 5 ) | ( (ebit & 7) << 2 ) | 1;
+ bcopy(h, f->data, 4); /* copy the h261 header */
+ if (ebit) { /* not aligned, so restart from previous byte */
+ sbit = 8 - ebit;
+ ebit = 0;
+ i--;
+ }
if (!cur)
first = f;
cur = f;
@@ -1393,7 +1412,7 @@
pthread_join(env->vthread, NULL);
ast_channel_lock(env->owner);
env->shutdown = 0;
- env->vthread = NULL;
+ /* XXX should remove the vthread reference */
/* uninitialize the local and remote video environments */
video_in_uninit(&env->in);
More information about the asterisk-commits
mailing list