[Ffmpeg-0.11.1 transplanted to Windows] [network problems] [Chinese device name problem]

Source: Internet
Author: User

Some of the problems described in this article are mainly related to windows. They do not focus on comparison with Linux, and continue with how to compile FFMPEG with vs08. Most of the content is collected on the Internet for reprinting.

----------------------------------------------------

This article lists some data structures related to interfaces: Linux-to-Windows program porting in Windows Network Programming

----------------------------------------------------

1. it's not actually a problem with network technology: If (INT) FDS [I]. FD> N), is the condition true or false (INT n =-1 ;)?

Let's take a look at the definition of the pollfd structure in Linux:

struct pollfd {    int fd;              /* file des to poll */    short events;  /* events to look for */    short revents; /* events that occurred */};

Let's take a look at the definition of the pollfd structure in Windows:

typedef struct pollfd {    SOCKET  fd;    SHORT   events;    SHORT   revents;} WSAPOLLFD, *PWSAPOLLFD, FAR *LPWSAPOLLFD;

typedef UINT_PTR        SOCKET;

Type mismatch, resulting in implicit conversion. In Windows, the conditional expression in the question is basically true.

2. wsastartup Function

int WSAStartup(  WORD wVersionRequested,  LPWSADATA lpWSAData);

3. Use of the getaddrinfo function in FFMPEG code

#if defined(_WIN32){int (WSAAPI *win_getaddrinfo)(const char *node, const char *service,  const struct addrinfo *hints,  struct addrinfo **res);char moduleName[36] = {0};int num_chars = 0;wchar_t moduleName_w[36] = {0};snprintf(moduleName, sizeof(moduleName), "ws2_32.dll");///* convert UTF-8 to wide chars */num_chars = MultiByteToWideChar(CP_UTF8, 0, moduleName, -1, NULL, 0);if (num_chars <= 0)return -1;MultiByteToWideChar(CP_UTF8, 0, moduleName, -1, moduleName_w, num_chars);HMODULE ws2mod = GetModuleHandle((const WCHAR *)moduleName_w);win_getaddrinfo = GetProcAddress(ws2mod, "getaddrinfo");if (win_getaddrinfo)return win_getaddrinfo(node, service, hints, res);}#endif

4. Is the connect 10035 (wsaewouldblock) error after ioctlsocket is set to non-blocking?

See connect 10035 Error

"In non-blocking mode, connect will return immediately instead of waiting for success. You need to select () to determine whether the operation is successful or not.
For (I = 0; I <totalsockets; I ++)
Fd_set (socketarray [I]-> socket, & readset );
If (Total = select (0, & readset, null) = socket_error)
{
Printf ("select () returned with error % d \ n", wsagetlasterror ());
Return;
}"

"10035 is not an error. The first change to the nonblock mode is that it cannot be considered as wrong when a socket_error occurs. Wsaewouldblock is a normal error code. It tells you that this operation cannot be completed immediately and you must wait for subsequent notifications. You can use the select method described above to check whether the link is successfully established"

Or look: http://www.verydemo.com/demo_c173_i9565.html

Socket sock = socket (af_inet, sock_stream, 0); // first create a socket If (sock = invalid_socket) {afxmessagebox ("failed to create a socket! "); Return 0;} sockaddr_in addrto; addrto. sin_family = af_inet; addrto. sin_port = htons (4000); addrto. sin_addr.s_un.s_addr = inet_addr (IP); // set to unsigned long ul = 1; int err; int ret = ioctlsocket (sock, fionbio, (unsigned long *) & UL); If (ret = socket_error) {err = wsagetlasterror (); closesocket (sock); sock = NULL; return false;} timeval; fd_set R; fd_zero (& R); fd_set (sock, & R); timeval. TV _sec = 1; // seconds timeval. TV _usec = 200; // millisecond // the above Code is to connect and return after 1.2 seconds. No matter whether it is connected or not, it will not be blocked. Connect (sock, (sockaddr *) & addrto, sizeof (sockaddr); ret = select (0, 0, & R, 0, & timeval); If (Ret <= 0) {char ch [20] = {0}; sprintf (CH, "and % s connection timeout, failed to get the original parameter", ip); MessageBox (CH, "error ", mb_iconstop); err = wsagetlasterror (); closesocket (sock); sock = NULL; return false ;}

By the way, record this problem: how to set a socket connection timeout

Yes, sometimes connect times out too long when the target cannot be reached. Set non-blocking First, connect returns immediately, and then sets it as blocking again. Finally, select to check whether the socket is ready.

5. In the dshow file of FFMPEG, enumerate the device names and match the device names transmitted from the upper layer.

Such as: unicode encoding of Chinese characters, commonly used Chinese characters UTF-8 encoding, Chinese GBK encoding table. The upper layer obtains the GBK code, but the following uses the UTF-8 to match, so it always fails.

Analysis of gb2312 UTF-8, ASCII Chinese Character

"ASCII, America standard code of information interchange, which is a one-byte 7-bit, exclusive to the United States. Europe also needs to be encoded, so the 8-bit bytes are all used, with IBM/ISO Latin-1. Then the third world countries, such as China and South Korea, must be extended. The text representation in the Chinese radiation area is very complicated, so the Unicode of the two bytes was born. However, there have been compatibility issues with several encodings. How can a Chinese file be read in the United States? A trade-off solution-UTF series. UTF, universal
Transformation format, which is a common conversion format. UTF-8 is a non-fixed length character representation, specific implementation can see relevant information ."

How to convert a Chinese character to an ascii code

"The ASCII code is obtained based on the HTTP encoding. First, you need to know the HTTP encoding of the word. First, go to Baidu post it, enter the word you want to view, and click search, for example, I enter "Ox", because the address is too long, and then click the upper left corner of Baidu paste next to "Ox", will appear relatively short address, this address is http://tieba.baidu.com/F? KW = % C5 % A3 kW = % C5 % A3 is the HTTP code. Remove % and change it to c5a3, use the calculator that comes with the system to convert it to 10 hexadecimal (start -- all programs -- accessories -- calculator), View -- science type, select hexadecimal, then input c5a3, and then select decimal, the above number will change to 50595, that is, ALT + 50595 can play "Ox ""

The following two sections of code are pasted. The conversion between GBK and UTF-8 calls the interface in windows. It doesn't matter whether the code is ugly or not.

//using cchar *gbk_to_utf8_c(const char *src_gbk, void *(* local_malloc)(size_t), void (* local_free)(void *)){int n;char *dst_utf8 = NULL;wchar_t *tmp = NULL;if (!src_gbk || !local_malloc || !local_free){return NULL;}n = MultiByteToWideChar(CP_ACP, 0, src_gbk, -1, NULL, 0);tmp = (wchar_t *)local_malloc(n*2+2);memset(tmp, 0, n * 2 + 2);MultiByteToWideChar(CP_ACP, 0, src_gbk, -1, tmp, n);n = WideCharToMultiByte(CP_UTF8, 0, tmp, -1, NULL, 0, NULL, NULL);dst_utf8 = (char *)local_malloc(n+1);memset(dst_utf8, 0, n + 1);WideCharToMultiByte(CP_UTF8, 0, tmp, -1, dst_utf8, n, NULL, NULL);local_free((void *)tmp);return dst_utf8;}char *utf8_to_gbk_c(const char *src_utf8, void *(* local_malloc)(size_t), void (* local_free)(void *)){int n = MultiByteToWideChar(CP_UTF8, 0, src_utf8, -1, NULL, 0);wchar_t *tmp = (wchar_t *)local_malloc(n*2+2);char *dst_gbk = NULL;memset(tmp, 0, n * 2 + 2);MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)src_utf8, -1, (LPWSTR)tmp, n);n = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)tmp, -1, NULL, 0, NULL, NULL);dst_gbk = (char *)local_malloc(n+1);memset(dst_gbk, 0, n + 1);WideCharToMultiByte(CP_ACP,0, (LPCWSTR)tmp, -1, dst_gbk, n, NULL, NULL);local_free((void *)tmp);return dst_gbk;}

For more information, see UTF-8, Unicode, gb2312 Format String Conversion C Language

In addition to the encoding problem, when the dshow interface is called (for some hardware device names, different Windows XP 7, Windows 7 usually has a prefix so that the device name is long ), the device friendly names are not completely obtained, but it is no problem to obtain them using the dsound interface. Some interfaces called by dshow are as follows:

*. Read the property of the device name Step 1: Call imoniker: bindtostorage to get a pointer to the ipropertybag interface. ipropertybag * ppropbag; hresult hR = pmoniker-> bindtostorage (0, 0, iid_ppv_args (& ppropbag); step2: Call ipropertybag: Read to read the property. variant var; variantinit (& var); // get description or friendly name. hR = ppropbag-> Read (L "Description", & var, 0 );

No. When the name is matched here, we have to compare the relationship between the two strings.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.