Repository: opencv
Issue: Disconnected IP camera  (opencv 2.4.9 and 3.0)
Labels: bug,auto-transferred,affected: 2.4,category: videoio(camera)

Transferred from http://code.opencv.org/issues/4199

```
|| Martin Šimák on 2015-02-16 18:23
|| Priority: High
|| Affected: 2.4.9 (latest release)
|| Category: highgui-camera
|| Tracker: Bug
|| Difficulty: Easy
|| PR: 
|| Platform: x86 / Windows
```
## Disconnected IP camera  (opencv 2.4.9 and 3.0)

```
I try to use my camera with opencv 2.4.9 and 3.0
When i use .open() on connected camera it´s fine.
But when i disconnect the camera and then use .open or .read or (VideoCapture)cap>>img or anything else that is working with camera output then program free/stuck/endless loop.

There is no chance to unfreeze without connection of camera. (i want to use multithreading and HttpClient to solve but...this is big BUG)

There is no chance to try the STATUS of camera (connected / disconnected) before using of .open() or .read()
```
## History
##### Steven Puttemans on 2015-02-17 07:35

```
Could you please run a debug session and look which cap interface from the highgui module is used after passing through the cap.cpp source file?
This will help us to identify which grabbing interface is broken and should be fixed.
-   Status changed from New to Open
```
##### Martin Šimák on 2015-02-17 09:04

```
Steven Puttemans wrote:
> Could you please run a debug session and look which cap interface from the highgui module is used after passing through the cap.cpp source file?
> This will help us to identify which grabbing interface is broken and should be fixed.

I start Local Windows Debugger but i am not sure if i am doing it right. 
When i step into is says i can view only dissasembly code (source information is missing for debug information for this module ) ...in CodeMap i saw it stucks in loop _ZwWaitForSingleObject&12 but i am not sure what i am doing.
If you want more accurate answer i need some help to debug right.

Maybe simmilar problem was http://code.opencv.org/issues/2786
I try to use that cap_ffmpeg_impl but it wont help its old issue
```
##### Martin Šimák on 2015-02-18 20:27

```
Steven Puttemans wrote:
> Could you please run a debug session and look which cap interface from the highgui module is used after passing through the cap.cpp source file?
> This will help us to identify which grabbing interface is broken and should be fixed.

Maybe it is simmilar with WinHTTP. 
When i try to use this code with BAD WEBSITE WinHttpSendRequest step into infinite loop...maybe same in opencv. 

But in WINHTTP you can do client.SetTimeouts(0U,1000U,1000U); after 1second..it stop

Please help me how to solve bad URL requestin in OPENCV

    DWORD dwSize = 0;
    DWORD dwDownloaded = 0;
    LPSTR pszOutBuffer;
    BOOL bResults = FALSE;
    HINTERNET hSession = NULL,
        hConnect = NULL,
        hRequest = NULL;

    // Use WinHttpOpen to obtain a session handle.
    hSession = WinHttpOpen(L"WinHTTP Example/1.0",
        WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
        WINHTTP_NO_PROXY_NAME,
        WINHTTP_NO_PROXY_BYPASS, 0);
    cout << "1 " << hSession << endl;
    WinHttpSetOption(hSession, WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS, NULL, NULL);
    // Specify an HTTP server.

    if (hSession)
        hConnect = WinHttpConnect(hSession, L"www.microsot.com",
        INTERNET_DEFAULT_HTTPS_PORT, 0);
    cout << "1.2 " << hConnect << endl;
    // Create an HTTP request handle.

    if (hConnect)
        hRequest = WinHttpOpenRequest(hConnect, L"GET", NULL,
        NULL, WINHTTP_NO_REFERER,
        WINHTTP_DEFAULT_ACCEPT_TYPES,
        WINHTTP_FLAG_SECURE);
    cout << "1.3 " << hRequest << endl;
    // Send a request.
    if (hRequest)
        bResults = WinHttpSendRequest(hRequest,
        WINHTTP_NO_ADDITIONAL_HEADERS, 0,
        WINHTTP_NO_REQUEST_DATA, 0,
        0, 0);
-   Assignee set to Steven Puttemans
```