PC Review


Reply
Thread Tools Rate Thread

adding byte at the begining of a byte[]

 
 
=?Utf-8?B?TGlvbmVsIFJleWVybw==?=
Guest
Posts: n/a
 
      27th May 2005

Hi,

In my C# video streaming app, I have to write a video frame to a socket. In
the socket I write video packet, which are composed of a 5 bytes header,
followed by the video frame bytes. My question is all about how to create
the packet (adding the 5 bytes header to the bytes of the frame) the most
efficiently.

The video frame is a ushort[], precisely : ushort[19200]
And I need the packet : byte[38405], with the byte 0-5 being the header,
and the rest being the frame data.

So I have 2 issues : adding the header, converting the ushort to bytes.

I am doing the copy of the ushort to the right place of the packet, by using
memory pointers (in unsage block) which I cast to bytes.

It is working good, but it is taking approximately 7 ms.
I would like to reduce this time... so I have two questios :

- How can I "cast", "convert", or "copy" the ushort[] frame data to the
byte[] packet ? Faster than what I already do

- Is it possible to add/insert the header bytes at the begining of the
ushort[] so that I do not need to copy the entire frame data.. ?
I find it stupid to copy the whole video data, simply to add a small
header... but I can't see how I can do it differently.... do you ?

Thanks a lot!

Lionel Reyero
 
Reply With Quote
 
 
 
 
Chris Tacke, eMVP
Guest
Posts: n/a
 
      27th May 2005
A linked list would allow the add, but copying from it will be a perf hit,
so that may be of no use. How are you getting frame data now? If you can
"get" it into the second byte of your array, then you could simply set the
first. Some massaging of the P/Invoke may be able to do that.

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate


"Lionel Reyero" <(E-Mail Removed)> wrote in message
news:B85F3058-35C2-4B5B-9DBD-(E-Mail Removed)...
>
> Hi,
>
> In my C# video streaming app, I have to write a video frame to a socket.
> In
> the socket I write video packet, which are composed of a 5 bytes header,
> followed by the video frame bytes. My question is all about how to
> create
> the packet (adding the 5 bytes header to the bytes of the frame) the most
> efficiently.
>
> The video frame is a ushort[], precisely : ushort[19200]
> And I need the packet : byte[38405], with the byte 0-5 being the header,
> and the rest being the frame data.
>
> So I have 2 issues : adding the header, converting the ushort to bytes.
>
> I am doing the copy of the ushort to the right place of the packet, by
> using
> memory pointers (in unsage block) which I cast to bytes.
>
> It is working good, but it is taking approximately 7 ms.
> I would like to reduce this time... so I have two questios :
>
> - How can I "cast", "convert", or "copy" the ushort[] frame data to the
> byte[] packet ? Faster than what I already do
>
> - Is it possible to add/insert the header bytes at the begining of the
> ushort[] so that I do not need to copy the entire frame data.. ?
> I find it stupid to copy the whole video data, simply to add a small
> header... but I can't see how I can do it differently.... do you ?
>
> Thanks a lot!
>
> Lionel Reyero



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Can you improve this code : Search Byte[] backwards for byte Pattern Family Tree Mike Microsoft C# .NET 0 26th Sep 2008 12:34 AM
Best Performance File Compare: MD5/SHA1 or Byte-by-Byte Checking? Mahmoud Al-Qudsi Microsoft C# .NET 6 4th Apr 2007 04:48 PM
Converting from byte to string and back to byte ends in different results? mfunkmann@yahoo.com Microsoft C# .NET 1 17th Dec 2006 02:53 PM
Convert from managed byte[] to void* and back to byte[] again jim.wiese@gmail.com Microsoft Dot NET 1 15th Feb 2005 06:11 AM
Convert native byte array (pointer) to managed byte[] Dave Microsoft Dot NET 1 13th Aug 2003 05:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:26 AM.