player.c 74.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Copyright 2014 Jacek Caban for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "wmp_private.h"

#include "wine/debug.h"
22
#include <nserror.h>
23
#include "wmpids.h"
24
#include "shlwapi.h"
25 26 27

WINE_DEFAULT_DEBUG_CHANNEL(wmp);

28 29 30 31
static ATOM player_msg_class;
static INIT_ONCE class_init_once;
static UINT WM_WMPEVENT;

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
static void update_state(WindowsMediaPlayer *wmp, LONG type, LONG state)
{
    DISPPARAMS dispparams;
    VARIANTARG params[1];

    dispparams.cArgs = 1;
    dispparams.cNamedArgs = 0;
    dispparams.rgdispidNamedArgs = NULL;
    dispparams.rgvarg = params;

    V_VT(params) = VT_UI4;
    V_UI4(params) = state;

    call_sink(wmp->wmpocx, type, &dispparams);
}

48 49 50 51 52
static inline WMPPlaylist *impl_from_IWMPPlaylist(IWMPPlaylist *iface)
{
    return CONTAINING_RECORD(iface, WMPPlaylist, IWMPPlaylist_iface);
}

53 54 55 56 57
static inline WMPMedia *impl_from_IWMPMedia(IWMPMedia *iface)
{
    return CONTAINING_RECORD(iface, WMPMedia, IWMPMedia_iface);
}

58 59 60 61 62
static inline WindowsMediaPlayer *impl_from_IWMPNetwork(IWMPNetwork *iface)
{
    return CONTAINING_RECORD(iface, WindowsMediaPlayer, IWMPNetwork_iface);
}

63 64 65 66 67
static inline WindowsMediaPlayer *impl_from_IWMPPlayer4(IWMPPlayer4 *iface)
{
    return CONTAINING_RECORD(iface, WindowsMediaPlayer, IWMPPlayer4_iface);
}

68 69 70 71 72
static inline WindowsMediaPlayer *impl_from_IWMPPlayer(IWMPPlayer *iface)
{
    return CONTAINING_RECORD(iface, WindowsMediaPlayer, IWMPPlayer_iface);
}

73 74 75 76 77
static inline WindowsMediaPlayer *impl_from_IWMPControls(IWMPControls *iface)
{
    return CONTAINING_RECORD(iface, WindowsMediaPlayer, IWMPControls_iface);
}

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
static HRESULT WINAPI WMPPlayer4_QueryInterface(IWMPPlayer4 *iface, REFIID riid, void **ppv)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    return IOleObject_QueryInterface(&This->IOleObject_iface, riid, ppv);
}

static ULONG WINAPI WMPPlayer4_AddRef(IWMPPlayer4 *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    return IOleObject_AddRef(&This->IOleObject_iface);
}

static ULONG WINAPI WMPPlayer4_Release(IWMPPlayer4 *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    return IOleObject_Release(&This->IOleObject_iface);
}

static HRESULT WINAPI WMPPlayer4_GetTypeInfoCount(IWMPPlayer4 *iface, UINT *pctinfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pctinfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_GetTypeInfo(IWMPPlayer4 *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_GetIDsOfNames(IWMPPlayer4 *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_Invoke(IWMPPlayer4 *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
        EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%d %s %d %x %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), lcid,
          wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_close(IWMPPlayer4 *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

136
static HRESULT WINAPI WMPPlayer4_get_URL(IWMPPlayer4 *iface, BSTR *url)
137 138
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
139 140 141

    TRACE("(%p)->(%p)\n", This, url);

142
    if (!This->media)
143
        return return_bstr(L"", url);
144 145

    return return_bstr(This->media->url, url);
146 147 148 149 150
}

static HRESULT WINAPI WMPPlayer4_put_URL(IWMPPlayer4 *iface, BSTR url)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
151
    IWMPMedia *media;
152
    HRESULT hres;
153

154
    TRACE("(%p)->(%s)\n", This, debugstr_w(url));
155

156
    hres = create_media_from_url(url, 0.0, &media);
157

158
    if (SUCCEEDED(hres)) {
159
        update_state(This, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsTransitioning);
160 161 162
        hres = IWMPPlayer4_put_currentMedia(iface, media);
        IWMPMedia_Release(media); /* put will addref */
    }
163 164
    if (SUCCEEDED(hres)) {
        update_state(This, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsReady);
165 166
        if (This->auto_start == VARIANT_TRUE)
            IWMPControls_play(&This->IWMPControls_iface);
167
    }
168

169
    return hres;
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
}

static HRESULT WINAPI WMPPlayer4_get_openState(IWMPPlayer4 *iface, WMPOpenState *pwmpos)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pwmpos);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_playState(IWMPPlayer4 *iface, WMPPlayState *pwmpps)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pwmpps);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_controls(IWMPPlayer4 *iface, IWMPControls **ppControl)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
189 190 191 192 193 194

    TRACE("(%p)->(%p)\n", This, ppControl);

    IWMPControls_AddRef(&This->IWMPControls_iface);
    *ppControl = &This->IWMPControls_iface;
    return S_OK;
195 196 197 198 199
}

static HRESULT WINAPI WMPPlayer4_get_settings(IWMPPlayer4 *iface, IWMPSettings **ppSettings)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
200 201 202 203 204 205

    TRACE("(%p)->(%p)\n", This, ppSettings);

    IWMPSettings_AddRef(&This->IWMPSettings_iface);
    *ppSettings = &This->IWMPSettings_iface;
    return S_OK;
206 207
}

208
static HRESULT WINAPI WMPPlayer4_get_currentMedia(IWMPPlayer4 *iface, IWMPMedia **media)
209 210
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
211 212 213 214 215 216

    TRACE("(%p)->(%p)\n", This, media);

    *media = NULL;

    if (This->media == NULL)
217
        return S_FALSE;
218 219

    return create_media_from_url(This->media->url, This->media->duration, media);
220 221 222 223 224
}

static HRESULT WINAPI WMPPlayer4_put_currentMedia(IWMPPlayer4 *iface, IWMPMedia *pMedia)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
225
    TRACE("(%p)->(%p)\n", This, pMedia);
226

227 228 229
    if(pMedia == NULL) {
        return E_POINTER;
    }
230
    update_state(This, DISPID_WMPCOREEVENT_OPENSTATECHANGE, wmposPlaylistChanging);
231
    if(This->media != NULL) {
232
        IWMPControls_stop(&This->IWMPControls_iface);
233
        IWMPMedia_Release(&This->media->IWMPMedia_iface);
234
    }
235 236 237
    update_state(This, DISPID_WMPCOREEVENT_OPENSTATECHANGE, wmposPlaylistChanged);
    update_state(This, DISPID_WMPCOREEVENT_OPENSTATECHANGE, wmposPlaylistOpenNoMedia);

238
    IWMPMedia_AddRef(pMedia);
239
    This->media = unsafe_impl_from_IWMPMedia(pMedia);
240
    return S_OK;
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
}

static HRESULT WINAPI WMPPlayer4_get_mediaCollection(IWMPPlayer4 *iface, IWMPMediaCollection **ppMediaCollection)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppMediaCollection);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_playlistCollection(IWMPPlayer4 *iface, IWMPPlaylistCollection **ppPlaylistCollection)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppPlaylistCollection);
    return E_NOTIMPL;
}

257
static HRESULT WINAPI WMPPlayer4_get_versionInfo(IWMPPlayer4 *iface, BSTR *version)
258 259
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
260 261 262 263 264 265

    TRACE("(%p)->(%p)\n", This, version);

    if (!version)
        return E_POINTER;

266
    return return_bstr(L"12.0.7601.16982", version);
267 268 269 270 271 272 273 274 275 276 277 278
}

static HRESULT WINAPI WMPPlayer4_launchURL(IWMPPlayer4 *iface, BSTR url)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(url));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_network(IWMPPlayer4 *iface, IWMPNetwork **ppQNI)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
279 280 281 282 283
    TRACE("(%p)->(%p)\n", This, ppQNI);

    IWMPNetwork_AddRef(&This->IWMPNetwork_iface);
    *ppQNI = &This->IWMPNetwork_iface;
    return S_OK;
284 285
}

286
static HRESULT WINAPI WMPPlayer4_get_currentPlaylist(IWMPPlayer4 *iface, IWMPPlaylist **playlist)
287 288
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
289 290 291 292 293 294 295 296

    TRACE("(%p)->(%p)\n", This, playlist);

    *playlist = NULL;

    if (This->playlist == NULL)
        return S_FALSE;

297
    return create_playlist(This->playlist->name, This->playlist->url, This->playlist->count, playlist);
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
}

static HRESULT WINAPI WMPPlayer4_put_currentPlaylist(IWMPPlayer4 *iface, IWMPPlaylist *pPL)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pPL);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_cdromCollection(IWMPPlayer4 *iface, IWMPCdromCollection **ppCdromCollection)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppCdromCollection);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_closedCaption(IWMPPlayer4 *iface, IWMPClosedCaption **ppClosedCaption)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppClosedCaption);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_isOnline(IWMPPlayer4 *iface, VARIANT_BOOL *pfOnline)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pfOnline);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_Error(IWMPPlayer4 *iface, IWMPError **ppError)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppError);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_Status(IWMPPlayer4 *iface, BSTR *pbstrStatus)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pbstrStatus);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_dvd(IWMPPlayer4 *iface, IWMPDVD **ppDVD)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppDVD);
    return E_NOTIMPL;
}

349
static HRESULT WINAPI WMPPlayer4_newPlaylist(IWMPPlayer4 *iface, BSTR name, BSTR url, IWMPPlaylist **playlist)
350 351
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
352 353 354

    TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(name), debugstr_w(url), playlist);

355 356
    /* FIXME: count should be the number of items in the playlist */
    return create_playlist(name, url, 0, playlist);
357 358
}

359
static HRESULT WINAPI WMPPlayer4_newMedia(IWMPPlayer4 *iface, BSTR url, IWMPMedia **media)
360 361
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
362 363 364 365

    TRACE("(%p)->(%s %p)\n", This, debugstr_w(url), media);

    return create_media_from_url(url, 0.0, media);
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
}

static HRESULT WINAPI WMPPlayer4_get_enabled(IWMPPlayer4 *iface, VARIANT_BOOL *pbEnabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pbEnabled);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_put_enabled(IWMPPlayer4 *iface, VARIANT_BOOL enabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%x)\n", This, enabled);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_fullScreen(IWMPPlayer4 *iface, VARIANT_BOOL *pbFullScreen)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pbFullScreen);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_put_fullScreen(IWMPPlayer4 *iface, VARIANT_BOOL fullscreen)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%x)\n", This, fullscreen);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_enableContextMenu(IWMPPlayer4 *iface, VARIANT_BOOL *pbEnableContextMenu)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pbEnableContextMenu);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_put_enableContextMenu(IWMPPlayer4 *iface, VARIANT_BOOL enable)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%x)\n", This, enable);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_put_uiMode(IWMPPlayer4 *iface, BSTR mode)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(mode));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_uiMode(IWMPPlayer4 *iface, BSTR *pbstrMode)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pbstrMode);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_stretchToFit(IWMPPlayer4 *iface, VARIANT_BOOL *enabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, enabled);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_put_stretchToFit(IWMPPlayer4 *iface, VARIANT_BOOL enabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%x)\n", This, enabled);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_windowlessVideo(IWMPPlayer4 *iface, VARIANT_BOOL *enabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, enabled);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_put_windowlessVideo(IWMPPlayer4 *iface, VARIANT_BOOL enabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%x)\n", This, enabled);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_isRemote(IWMPPlayer4 *iface, VARIANT_BOOL *pvarfIsRemote)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, pvarfIsRemote);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_get_playerApplication(IWMPPlayer4 *iface, IWMPPlayerApplication **ppIWMPPlayerApplication)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%p)\n", This, ppIWMPPlayerApplication);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlayer4_openPlayer(IWMPPlayer4 *iface, BSTR url)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(url));
    return E_NOTIMPL;
}

473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
static HRESULT WINAPI WMPPlayer_QueryInterface(IWMPPlayer *iface, REFIID riid, void **ppv)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_QueryInterface(&This->IWMPPlayer4_iface, riid, ppv);
}

static ULONG WINAPI WMPPlayer_AddRef(IWMPPlayer *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_AddRef(&This->IWMPPlayer4_iface);
}

static ULONG WINAPI WMPPlayer_Release(IWMPPlayer *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_Release(&This->IWMPPlayer4_iface);
}

static HRESULT WINAPI WMPPlayer_GetTypeInfoCount(IWMPPlayer *iface, UINT *pctinfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_GetTypeInfoCount(&This->IWMPPlayer4_iface, pctinfo);
}

static HRESULT WINAPI WMPPlayer_GetTypeInfo(IWMPPlayer *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);

    return WMPPlayer4_GetTypeInfo(&This->IWMPPlayer4_iface, iTInfo,
        lcid, ppTInfo);
}

static HRESULT WINAPI WMPPlayer_GetIDsOfNames(IWMPPlayer *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_GetIDsOfNames(&This->IWMPPlayer4_iface, riid,
        rgszNames, cNames, lcid, rgDispId);
}

static HRESULT WINAPI WMPPlayer_Invoke(IWMPPlayer *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
        EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_Invoke(&This->IWMPPlayer4_iface, dispIdMember,
        riid, lcid, wFlags, pDispParams, pVarResult,
        pExcepInfo, puArgErr);
}

static HRESULT WINAPI WMPPlayer_close(IWMPPlayer *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_close(&This->IWMPPlayer4_iface);
}

static HRESULT WINAPI WMPPlayer_get_URL(IWMPPlayer *iface, BSTR *pbstrURL)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_URL(&This->IWMPPlayer4_iface, pbstrURL);
}

static HRESULT WINAPI WMPPlayer_put_URL(IWMPPlayer *iface, BSTR url)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_put_URL(&This->IWMPPlayer4_iface, url);
}

static HRESULT WINAPI WMPPlayer_get_openState(IWMPPlayer *iface, WMPOpenState *pwmpos)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_openState(&This->IWMPPlayer4_iface, pwmpos);
}

static HRESULT WINAPI WMPPlayer_get_playState(IWMPPlayer *iface, WMPPlayState *pwmpps)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_playState(&This->IWMPPlayer4_iface, pwmpps);
}

static HRESULT WINAPI WMPPlayer_get_controls(IWMPPlayer *iface, IWMPControls **ppControl)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_controls(&This->IWMPPlayer4_iface, ppControl);
}

static HRESULT WINAPI WMPPlayer_get_settings(IWMPPlayer *iface, IWMPSettings **ppSettings)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_settings(&This->IWMPPlayer4_iface, ppSettings);
}

static HRESULT WINAPI WMPPlayer_get_currentMedia(IWMPPlayer *iface, IWMPMedia **ppMedia)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_currentMedia(&This->IWMPPlayer4_iface, ppMedia);
}

static HRESULT WINAPI WMPPlayer_put_currentMedia(IWMPPlayer *iface, IWMPMedia *pMedia)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_put_currentMedia(&This->IWMPPlayer4_iface, pMedia);
}

static HRESULT WINAPI WMPPlayer_get_mediaCollection(IWMPPlayer *iface, IWMPMediaCollection **ppMediaCollection)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_mediaCollection(&This->IWMPPlayer4_iface, ppMediaCollection);
}

static HRESULT WINAPI WMPPlayer_get_playlistCollection(IWMPPlayer *iface, IWMPPlaylistCollection **ppPlaylistCollection)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_playlistCollection(&This->IWMPPlayer4_iface, ppPlaylistCollection);
}

static HRESULT WINAPI WMPPlayer_get_versionInfo(IWMPPlayer *iface, BSTR *version)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_versionInfo(&This->IWMPPlayer4_iface, version);
}

static HRESULT WINAPI WMPPlayer_launchURL(IWMPPlayer *iface, BSTR url)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_launchURL(&This->IWMPPlayer4_iface, url);
}

static HRESULT WINAPI WMPPlayer_get_network(IWMPPlayer *iface, IWMPNetwork **ppQNI)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_network(&This->IWMPPlayer4_iface, ppQNI);
}

static HRESULT WINAPI WMPPlayer_get_currentPlaylist(IWMPPlayer *iface, IWMPPlaylist **ppPL)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_currentPlaylist(&This->IWMPPlayer4_iface, ppPL);
}

static HRESULT WINAPI WMPPlayer_put_currentPlaylist(IWMPPlayer *iface, IWMPPlaylist *pPL)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_put_currentPlaylist(&This->IWMPPlayer4_iface, pPL);
}

static HRESULT WINAPI WMPPlayer_get_cdromCollection(IWMPPlayer *iface, IWMPCdromCollection **ppCdromCollection)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_cdromCollection(&This->IWMPPlayer4_iface, ppCdromCollection);
}

static HRESULT WINAPI WMPPlayer_get_closedCaption(IWMPPlayer *iface, IWMPClosedCaption **ppClosedCaption)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_closedCaption(&This->IWMPPlayer4_iface, ppClosedCaption);
}

static HRESULT WINAPI WMPPlayer_get_isOnline(IWMPPlayer *iface, VARIANT_BOOL *pfOnline)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_isOnline(&This->IWMPPlayer4_iface, pfOnline);
}

static HRESULT WINAPI WMPPlayer_get_Error(IWMPPlayer *iface, IWMPError **ppError)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_Error(&This->IWMPPlayer4_iface, ppError);
}

static HRESULT WINAPI WMPPlayer_get_Status(IWMPPlayer *iface, BSTR *pbstrStatus)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_Status(&This->IWMPPlayer4_iface, pbstrStatus);
}

static HRESULT WINAPI WMPPlayer_get_enabled(IWMPPlayer *iface, VARIANT_BOOL *pbEnabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_enabled(&This->IWMPPlayer4_iface, pbEnabled);
}

static HRESULT WINAPI WMPPlayer_put_enabled(IWMPPlayer *iface, VARIANT_BOOL enabled)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_put_enabled(&This->IWMPPlayer4_iface, enabled);
}

static HRESULT WINAPI WMPPlayer_get_fullScreen(IWMPPlayer *iface, VARIANT_BOOL *pbFullScreen)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_fullScreen(&This->IWMPPlayer4_iface, pbFullScreen);
}

static HRESULT WINAPI WMPPlayer_put_fullScreen(IWMPPlayer *iface, VARIANT_BOOL fullscreen)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_put_fullScreen(&This->IWMPPlayer4_iface, fullscreen);
}

static HRESULT WINAPI WMPPlayer_get_enableContextMenu(IWMPPlayer *iface, VARIANT_BOOL *pbEnableContextMenu)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_enableContextMenu(&This->IWMPPlayer4_iface, pbEnableContextMenu);
}

static HRESULT WINAPI WMPPlayer_put_enableContextMenu(IWMPPlayer *iface, VARIANT_BOOL enable)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_put_enableContextMenu(&This->IWMPPlayer4_iface, enable);
}

static HRESULT WINAPI WMPPlayer_put_uiMode(IWMPPlayer *iface, BSTR mode)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_put_uiMode(&This->IWMPPlayer4_iface, mode);
}

static HRESULT WINAPI WMPPlayer_get_uiMode(IWMPPlayer *iface, BSTR *pbstrMode)
{
    WindowsMediaPlayer *This = impl_from_IWMPPlayer(iface);
    return WMPPlayer4_get_uiMode(&This->IWMPPlayer4_iface, pbstrMode);
}

static IWMPPlayerVtbl WMPPlayerVtbl = {
    WMPPlayer_QueryInterface,
    WMPPlayer_AddRef,
    WMPPlayer_Release,
    WMPPlayer_GetTypeInfoCount,
    WMPPlayer_GetTypeInfo,
    WMPPlayer_GetIDsOfNames,
    WMPPlayer_Invoke,
    WMPPlayer_close,
    WMPPlayer_get_URL,
    WMPPlayer_put_URL,
    WMPPlayer_get_openState,
    WMPPlayer_get_playState,
    WMPPlayer_get_controls,
    WMPPlayer_get_settings,
    WMPPlayer_get_currentMedia,
    WMPPlayer_put_currentMedia,
    WMPPlayer_get_mediaCollection,
    WMPPlayer_get_playlistCollection,
    WMPPlayer_get_versionInfo,
    WMPPlayer_launchURL,
    WMPPlayer_get_network,
    WMPPlayer_get_currentPlaylist,
    WMPPlayer_put_currentPlaylist,
    WMPPlayer_get_cdromCollection,
    WMPPlayer_get_closedCaption,
    WMPPlayer_get_isOnline,
    WMPPlayer_get_Error,
    WMPPlayer_get_Status,
    WMPPlayer_get_enabled,
    WMPPlayer_put_enabled,
    WMPPlayer_get_fullScreen,
    WMPPlayer_put_fullScreen,
    WMPPlayer_get_enableContextMenu,
    WMPPlayer_put_enableContextMenu,
    WMPPlayer_put_uiMode,
    WMPPlayer_get_uiMode,
};


738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
static IWMPPlayer4Vtbl WMPPlayer4Vtbl = {
    WMPPlayer4_QueryInterface,
    WMPPlayer4_AddRef,
    WMPPlayer4_Release,
    WMPPlayer4_GetTypeInfoCount,
    WMPPlayer4_GetTypeInfo,
    WMPPlayer4_GetIDsOfNames,
    WMPPlayer4_Invoke,
    WMPPlayer4_close,
    WMPPlayer4_get_URL,
    WMPPlayer4_put_URL,
    WMPPlayer4_get_openState,
    WMPPlayer4_get_playState,
    WMPPlayer4_get_controls,
    WMPPlayer4_get_settings,
    WMPPlayer4_get_currentMedia,
    WMPPlayer4_put_currentMedia,
    WMPPlayer4_get_mediaCollection,
    WMPPlayer4_get_playlistCollection,
    WMPPlayer4_get_versionInfo,
    WMPPlayer4_launchURL,
    WMPPlayer4_get_network,
    WMPPlayer4_get_currentPlaylist,
    WMPPlayer4_put_currentPlaylist,
    WMPPlayer4_get_cdromCollection,
    WMPPlayer4_get_closedCaption,
    WMPPlayer4_get_isOnline,
    WMPPlayer4_get_Error,
    WMPPlayer4_get_Status,
    WMPPlayer4_get_dvd,
    WMPPlayer4_newPlaylist,
    WMPPlayer4_newMedia,
    WMPPlayer4_get_enabled,
    WMPPlayer4_put_enabled,
    WMPPlayer4_get_fullScreen,
    WMPPlayer4_put_fullScreen,
    WMPPlayer4_get_enableContextMenu,
    WMPPlayer4_put_enableContextMenu,
    WMPPlayer4_put_uiMode,
    WMPPlayer4_get_uiMode,
    WMPPlayer4_get_stretchToFit,
    WMPPlayer4_put_stretchToFit,
    WMPPlayer4_get_windowlessVideo,
    WMPPlayer4_put_windowlessVideo,
    WMPPlayer4_get_isRemote,
    WMPPlayer4_get_playerApplication,
    WMPPlayer4_openPlayer
};

787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
static inline WindowsMediaPlayer *impl_from_IWMPSettings(IWMPSettings *iface)
{
    return CONTAINING_RECORD(iface, WindowsMediaPlayer, IWMPSettings_iface);
}

static HRESULT WINAPI WMPSettings_QueryInterface(IWMPSettings *iface, REFIID riid, void **ppv)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    return IOleObject_QueryInterface(&This->IOleObject_iface, riid, ppv);
}

static ULONG WINAPI WMPSettings_AddRef(IWMPSettings *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    return IOleObject_AddRef(&This->IOleObject_iface);
}

static ULONG WINAPI WMPSettings_Release(IWMPSettings *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    return IOleObject_Release(&This->IOleObject_iface);
}

static HRESULT WINAPI WMPSettings_GetTypeInfoCount(IWMPSettings *iface, UINT *pctinfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%p)\n", This, pctinfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_GetTypeInfo(IWMPSettings *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_GetIDsOfNames(IWMPSettings *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_Invoke(IWMPSettings *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
        EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%d %s %d %x %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), lcid,
          wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_isAvailable(IWMPSettings *iface, BSTR item, VARIANT_BOOL *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(item), p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_autoStart(IWMPSettings *iface, VARIANT_BOOL *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
853 854 855 856 857
    TRACE("(%p)->(%p)\n", This, p);
    if (!p)
        return E_POINTER;
    *p = This->auto_start;
    return S_OK;
858 859 860 861 862
}

static HRESULT WINAPI WMPSettings_put_autoStart(IWMPSettings *iface, VARIANT_BOOL v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
863 864 865
    TRACE("(%p)->(%x)\n", This, v);
    This->auto_start = v;
    return S_OK;
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
}

static HRESULT WINAPI WMPSettings_get_baseURL(IWMPSettings *iface, BSTR *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_put_baseURL(IWMPSettings *iface, BSTR v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_defaultFrame(IWMPSettings *iface, BSTR *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_put_defaultFrame(IWMPSettings *iface, BSTR v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_invokeURLs(IWMPSettings *iface, VARIANT_BOOL *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
899 900 901 902 903 904 905

    TRACE("(%p)->(%p)\n", This, p);

    if (!p)
        return E_POINTER;
    *p = This->invoke_urls;
    return S_OK;
906 907 908 909 910
}

static HRESULT WINAPI WMPSettings_put_invokeURLs(IWMPSettings *iface, VARIANT_BOOL v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
911
    /* Leaving as FIXME as we don't currently use this */
912
    FIXME("(%p)->(%x)\n", This, v);
913 914
    This->invoke_urls = v;
    return S_OK;
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
}

static HRESULT WINAPI WMPSettings_get_mute(IWMPSettings *iface, VARIANT_BOOL *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_put_mute(IWMPSettings *iface, VARIANT_BOOL v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%x)\n", This, v);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_playCount(IWMPSettings *iface, LONG *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_put_playCount(IWMPSettings *iface, LONG v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%d)\n", This, v);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_rate(IWMPSettings *iface, double *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_put_rate(IWMPSettings *iface, double v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%lf)\n", This, v);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_balance(IWMPSettings *iface, LONG *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_put_balance(IWMPSettings *iface, LONG v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%d)\n", This, v);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_volume(IWMPSettings *iface, LONG *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
976 977 978 979 980
    TRACE("(%p)->(%p)\n", This, p);
    if (!p)
        return E_POINTER;
    *p = This->volume;
    return S_OK;
981 982 983 984 985
}

static HRESULT WINAPI WMPSettings_put_volume(IWMPSettings *iface, LONG v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
986 987
    TRACE("(%p)->(%d)\n", This, v);
    This->volume = v;
988 989 990 991 992 993 994 995 996
    if (!This->filter_graph)
        return S_OK;

    /* IBasicAudio -   [-10000, 0], wmp - [0, 100] */
    v = 10000 * v / 100 - 10000;
    if (!This->basic_audio)
        return S_FALSE;

    return IBasicAudio_put_Volume(This->basic_audio, v);
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
}

static HRESULT WINAPI WMPSettings_getMode(IWMPSettings *iface, BSTR mode, VARIANT_BOOL *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(mode), p);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_setMode(IWMPSettings *iface, BSTR mode, VARIANT_BOOL v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
    FIXME("(%p)->(%s %x)\n", This, debugstr_w(mode), v);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPSettings_get_enableErrorDialogs(IWMPSettings *iface, VARIANT_BOOL *p)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
1016 1017 1018 1019 1020 1021 1022

    TRACE("(%p)->(%p)\n", This, p);

    if (!p)
        return E_POINTER;
    *p = This->enable_error_dialogs;
    return S_OK;
1023 1024 1025 1026 1027
}

static HRESULT WINAPI WMPSettings_put_enableErrorDialogs(IWMPSettings *iface, VARIANT_BOOL v)
{
    WindowsMediaPlayer *This = impl_from_IWMPSettings(iface);
1028
    /* Leaving as FIXME as we don't currently use this */
1029
    FIXME("(%p)->(%x)\n", This, v);
1030 1031
    This->enable_error_dialogs = v;
    return S_OK;
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
}

static const IWMPSettingsVtbl WMPSettingsVtbl = {
    WMPSettings_QueryInterface,
    WMPSettings_AddRef,
    WMPSettings_Release,
    WMPSettings_GetTypeInfoCount,
    WMPSettings_GetTypeInfo,
    WMPSettings_GetIDsOfNames,
    WMPSettings_Invoke,
    WMPSettings_get_isAvailable,
    WMPSettings_get_autoStart,
    WMPSettings_put_autoStart,
    WMPSettings_get_baseURL,
    WMPSettings_put_baseURL,
    WMPSettings_get_defaultFrame,
    WMPSettings_put_defaultFrame,
    WMPSettings_get_invokeURLs,
    WMPSettings_put_invokeURLs,
    WMPSettings_get_mute,
    WMPSettings_put_mute,
    WMPSettings_get_playCount,
    WMPSettings_put_playCount,
    WMPSettings_get_rate,
    WMPSettings_put_rate,
    WMPSettings_get_balance,
    WMPSettings_put_balance,
    WMPSettings_get_volume,
    WMPSettings_put_volume,
    WMPSettings_getMode,
    WMPSettings_setMode,
    WMPSettings_get_enableErrorDialogs,
    WMPSettings_put_enableErrorDialogs
};

1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
static HRESULT WINAPI WMPNetwork_QueryInterface(IWMPNetwork *iface, REFIID riid, void **ppv)
{
    if(IsEqualGUID(riid, &IID_IDispatch)) {
        *ppv = iface;
    }else if(IsEqualGUID(riid, &IID_IWMPNetwork)) {
        *ppv = iface;
    }else {
        WARN("Unsupported interface (%s)\n", wine_dbgstr_guid(riid));
        *ppv = NULL;
        return E_NOINTERFACE;
    }

    IUnknown_AddRef((IUnknown*)*ppv);
    return S_OK;
}

static ULONG WINAPI WMPNetwork_AddRef(IWMPNetwork *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    return IOleObject_AddRef(&This->IOleObject_iface);
}

static ULONG WINAPI WMPNetwork_Release(IWMPNetwork *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    return IOleObject_Release(&This->IOleObject_iface);
}

static HRESULT WINAPI WMPNetwork_GetTypeInfoCount(IWMPNetwork *iface, UINT *pctinfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, pctinfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_GetTypeInfo(IWMPNetwork *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_GetIDsOfNames(IWMPNetwork *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_Invoke(IWMPNetwork *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
        EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%d %s %d %x %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), lcid,
          wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_bandWidth(IWMPNetwork *iface, LONG *plBandwidth)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plBandwidth);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_recoveredPackets(IWMPNetwork *iface, LONG *plRecoveredPackets)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plRecoveredPackets);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_sourceProtocol(IWMPNetwork *iface, BSTR *pbstrSourceProtocol)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, pbstrSourceProtocol);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_receivedPackets(IWMPNetwork *iface, LONG *plReceivedPackets)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plReceivedPackets);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_lostPackets(IWMPNetwork *iface, LONG *plLostPackets)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plLostPackets);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_receptionQuality(IWMPNetwork *iface, LONG *plReceptionQuality)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plReceptionQuality);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_bufferingCount(IWMPNetwork *iface, LONG *plBufferingCount)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plBufferingCount);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_bufferingProgress(IWMPNetwork *iface, LONG *plBufferingProgress)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
    TRACE("(%p)->(%p)\n", This, plBufferingProgress);
    if (!This->filter_graph) {
        return S_FALSE;
    }
    /* Ideally we would use IAMOpenProgress for URL reader but we don't have it in wine (yet)
     * For file sources FileAsyncReader->Length should work
     * */
    FIXME("stub: Returning buffering progress 100\n");
    *plBufferingProgress = 100;

    return S_OK;
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
}

static HRESULT WINAPI WMPNetwork_get_bufferingTime(IWMPNetwork *iface, LONG *plBufferingTime)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plBufferingTime);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_put_bufferingTime(IWMPNetwork *iface, LONG lBufferingTime)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%d)\n", This, lBufferingTime);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_frameRate(IWMPNetwork *iface, LONG *plFrameRate)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plFrameRate);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_maxBitRate(IWMPNetwork *iface, LONG *plBitRate)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plBitRate);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_bitRate(IWMPNetwork *iface, LONG *plBitRate)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plBitRate);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_getProxySettings(IWMPNetwork *iface, BSTR bstrProtocol, LONG *plProxySetting)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %p)\n", This, debugstr_w(bstrProtocol), plProxySetting);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_setProxySettings(IWMPNetwork *iface, BSTR bstrProtocol, LONG lProxySetting)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %d)\n", This, debugstr_w(bstrProtocol), lProxySetting);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_getProxyName(IWMPNetwork *iface, BSTR bstrProtocol, BSTR *pbstrProxyName)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %p)\n", This, debugstr_w(bstrProtocol), pbstrProxyName);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_setProxyName(IWMPNetwork *iface, BSTR bstrProtocol, BSTR bstrProxyName)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %s)\n", This, debugstr_w(bstrProtocol), debugstr_w(bstrProxyName));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_getProxyPort(IWMPNetwork *iface, BSTR bstrProtocol, LONG *plProxyPort)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %p)\n", This, debugstr_w(bstrProtocol), plProxyPort);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_setProxyPort(IWMPNetwork *iface, BSTR bstrProtocol, LONG lProxyPort)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %d)\n", This, debugstr_w(bstrProtocol), lProxyPort);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_getProxyExceptionList(IWMPNetwork *iface, BSTR bstrProtocol, BSTR *pbstrExceptionList)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %p)\n", This, debugstr_w(bstrProtocol), pbstrExceptionList);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_setProxyExceptionList(IWMPNetwork *iface, BSTR bstrProtocol, BSTR bstrExceptionList)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %s)\n", This, debugstr_w(bstrProtocol), debugstr_w(bstrExceptionList));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_getProxyBypassForLocal(IWMPNetwork *iface, BSTR bstrProtocol, VARIANT_BOOL *pfBypassForLocal)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %p)\n", This, debugstr_w(bstrProtocol), pfBypassForLocal);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_setProxyBypassForLocal(IWMPNetwork *iface, BSTR bstrProtocol, VARIANT_BOOL fBypassForLocal)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%s, %d)\n", This, debugstr_w(bstrProtocol), fBypassForLocal);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_maxBandwidth(IWMPNetwork *iface, LONG *plMaxBandwidth)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plMaxBandwidth);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_put_maxBandwidth(IWMPNetwork *iface, LONG lMaxBandwidth)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%d)\n", This, lMaxBandwidth);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_downloadProgress(IWMPNetwork *iface, LONG *plDownloadProgress)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326
    TRACE("(%p)->(%p)\n", This, plDownloadProgress);
    if (!This->filter_graph) {
        return S_FALSE;
    }
    /* Ideally we would use IAMOpenProgress for URL reader but we don't have it in wine (yet)
     * For file sources FileAsyncReader->Length could work or it should just be
     * 100
     * */
    FIXME("stub: Returning download progress 100\n");
    *plDownloadProgress = 100;

    return S_OK;
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380
}

static HRESULT WINAPI WMPNetwork_get_encodedFrameRate(IWMPNetwork *iface, LONG *plFrameRate)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plFrameRate);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPNetwork_get_framesSkipped(IWMPNetwork *iface, LONG *plFrames)
{
    WindowsMediaPlayer *This = impl_from_IWMPNetwork(iface);
    FIXME("(%p)->(%p)\n", This, plFrames);
    return E_NOTIMPL;
}

static const IWMPNetworkVtbl WMPNetworkVtbl = {
    WMPNetwork_QueryInterface,
    WMPNetwork_AddRef,
    WMPNetwork_Release,
    WMPNetwork_GetTypeInfoCount,
    WMPNetwork_GetTypeInfo,
    WMPNetwork_GetIDsOfNames,
    WMPNetwork_Invoke,
    WMPNetwork_get_bandWidth,
    WMPNetwork_get_recoveredPackets,
    WMPNetwork_get_sourceProtocol,
    WMPNetwork_get_receivedPackets,
    WMPNetwork_get_lostPackets,
    WMPNetwork_get_receptionQuality,
    WMPNetwork_get_bufferingCount,
    WMPNetwork_get_bufferingProgress,
    WMPNetwork_get_bufferingTime,
    WMPNetwork_put_bufferingTime,
    WMPNetwork_get_frameRate,
    WMPNetwork_get_maxBitRate,
    WMPNetwork_get_bitRate,
    WMPNetwork_getProxySettings,
    WMPNetwork_setProxySettings,
    WMPNetwork_getProxyName,
    WMPNetwork_setProxyName,
    WMPNetwork_getProxyPort,
    WMPNetwork_setProxyPort,
    WMPNetwork_getProxyExceptionList,
    WMPNetwork_setProxyExceptionList,
    WMPNetwork_getProxyBypassForLocal,
    WMPNetwork_setProxyBypassForLocal,
    WMPNetwork_get_maxBandwidth,
    WMPNetwork_put_maxBandwidth,
    WMPNetwork_get_downloadProgress,
    WMPNetwork_get_encodedFrameRate,
    WMPNetwork_get_framesSkipped,
};

1381
static HRESULT WINAPI WMPControls_QueryInterface(IWMPControls *iface, REFIID riid, void **ppv)
1382
{
1383 1384 1385
    if(IsEqualGUID(riid, &IID_IUnknown)) {
        *ppv = iface;
    }else if(IsEqualGUID(riid, &IID_IDispatch)) {
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
        *ppv = iface;
    }else if(IsEqualGUID(riid, &IID_IWMPControls)) {
        *ppv = iface;
    }else {
        WARN("Unsupported interface (%s)\n", wine_dbgstr_guid(riid));
        *ppv = NULL;
        return E_NOINTERFACE;
    }

    IUnknown_AddRef((IUnknown*)*ppv);
    return S_OK;
}

static ULONG WINAPI WMPControls_AddRef(IWMPControls *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    return IOleObject_AddRef(&This->IOleObject_iface);
}

static ULONG WINAPI WMPControls_Release(IWMPControls *iface)
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    return IOleObject_Release(&This->IOleObject_iface);
}

static HRESULT WINAPI WMPControls_GetTypeInfoCount(IWMPControls *iface, UINT *pctinfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%p)\n", This, pctinfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPControls_GetTypeInfo(IWMPControls *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPControls_GetIDsOfNames(IWMPControls *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPControls_Invoke(IWMPControls *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
        EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%d %s %d %x %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), lcid,
          wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPControls_get_isAvailable(IWMPControls *iface, BSTR bstrItem, VARIANT_BOOL *pIsAvailable)
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
1447 1448 1449
    TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrItem), pIsAvailable);
    if (!This->filter_graph) {
        *pIsAvailable = VARIANT_FALSE;
1450
    } else if (wcscmp(L"currentPosition", bstrItem) == 0) {
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460
        DWORD capabilities;
        IMediaSeeking_GetCapabilities(This->media_seeking, &capabilities);
        *pIsAvailable = (capabilities & AM_SEEKING_CanSeekAbsolute) ?
            VARIANT_TRUE : VARIANT_FALSE;
    } else {
        FIXME("%s not implemented\n", debugstr_w(bstrItem));
        return E_NOTIMPL;
    }

    return S_OK;
1461 1462
}

1463
static HRESULT WINAPI WMPControls_play(IWMPControls *iface)
1464
{
1465
    HRESULT hres = S_OK;
1466
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
1467 1468 1469

    TRACE("(%p)\n", This);

1470
    if (!This->media) {
1471 1472 1473 1474 1475 1476 1477 1478 1479
        return NS_S_WMPCORE_COMMAND_NOT_AVAILABLE;
    }

    if (!This->filter_graph) {
        hres = CoCreateInstance(&CLSID_FilterGraph,
                NULL,
                CLSCTX_INPROC_SERVER,
                &IID_IGraphBuilder,
                (void **)&This->filter_graph);
1480 1481
        update_state(This, DISPID_WMPCOREEVENT_OPENSTATECHANGE, wmposOpeningUnknownURL);

1482
        if (SUCCEEDED(hres))
1483
            hres = IGraphBuilder_RenderFile(This->filter_graph, This->media->url, NULL);
1484 1485
        if (SUCCEEDED(hres))
            update_state(This, DISPID_WMPCOREEVENT_OPENSTATECHANGE, wmposMediaOpen);
1486 1487 1488
        if (SUCCEEDED(hres))
            hres = IGraphBuilder_QueryInterface(This->filter_graph, &IID_IMediaControl,
                    (void**)&This->media_control);
1489
        if (SUCCEEDED(hres))
1490 1491 1492 1493
            hres = IGraphBuilder_QueryInterface(This->filter_graph, &IID_IMediaSeeking,
                    (void**)&This->media_seeking);
        if (SUCCEEDED(hres))
            hres = IMediaSeeking_SetTimeFormat(This->media_seeking, &TIME_FORMAT_MEDIA_TIME);
1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507
        if (SUCCEEDED(hres))
            hres = IGraphBuilder_QueryInterface(This->filter_graph, &IID_IMediaEvent,
                    (void**)&This->media_event);
        if (SUCCEEDED(hres))
        {
            IMediaEventEx *media_event_ex = NULL;
            hres = IGraphBuilder_QueryInterface(This->filter_graph, &IID_IMediaEventEx,
                    (void**)&media_event_ex);
            if (SUCCEEDED(hres)) {
                hres = IMediaEventEx_SetNotifyWindow(media_event_ex, (OAHWND)This->msg_window,
                        WM_WMPEVENT, (LONG_PTR)This);
                IMediaEventEx_Release(media_event_ex);
            }
        }
1508 1509 1510 1511
        if (SUCCEEDED(hres))
            hres = IGraphBuilder_QueryInterface(This->filter_graph, &IID_IBasicAudio, (void**)&This->basic_audio);
        if (SUCCEEDED(hres))
            hres = IWMPSettings_put_volume(&This->IWMPSettings_iface, This->volume);
1512 1513
    }

1514 1515
    update_state(This, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsTransitioning);

1516 1517 1518 1519 1520 1521
    if (SUCCEEDED(hres))
        hres = IMediaControl_Run(This->media_control);

    if (hres == S_FALSE) {
        hres = S_OK; /* S_FALSE will mean that graph is transitioning and that is fine */
    }
1522 1523

    if (SUCCEEDED(hres)) {
1524
        LONGLONG duration;
1525
        update_state(This, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsPlaying);
1526
        if (SUCCEEDED(IMediaSeeking_GetDuration(This->media_seeking, &duration)))
1527
            This->media->duration = (DOUBLE)duration / 10000000.0f;
1528 1529 1530 1531
    } else {
        update_state(This, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsUndefined);
    }

1532
    return hres;
1533 1534
}

1535
static HRESULT WINAPI WMPControls_stop(IWMPControls *iface)
1536
{
1537
    HRESULT hres = S_OK;
1538
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
1539 1540 1541 1542 1543 1544 1545 1546
    TRACE("(%p)\n", This);
    if (!This->filter_graph) {
        return NS_S_WMPCORE_COMMAND_NOT_AVAILABLE;
    }
    if (This->media_control) {
        hres = IMediaControl_Stop(This->media_control);
        IMediaControl_Release(This->media_control);
    }
1547 1548 1549
    if (This->media_event) {
        IMediaEvent_Release(This->media_event);
    }
1550 1551 1552
    if (This->media_seeking) {
        IMediaSeeking_Release(This->media_seeking);
    }
1553 1554 1555
    if (This->basic_audio) {
        IBasicAudio_Release(This->basic_audio);
    }
1556 1557 1558
    IGraphBuilder_Release(This->filter_graph);
    This->filter_graph = NULL;
    This->media_control = NULL;
1559
    This->media_event = NULL;
1560
    This->media_seeking = NULL;
1561
    This->basic_audio = NULL;
1562

1563 1564
    update_state(This, DISPID_WMPCOREEVENT_OPENSTATECHANGE, wmposPlaylistOpenNoMedia);
    update_state(This, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsStopped);
1565
    return hres;
1566 1567
}

1568
static HRESULT WINAPI WMPControls_pause(IWMPControls *iface)
1569 1570 1571 1572 1573 1574
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

1575
static HRESULT WINAPI WMPControls_fastForward(IWMPControls *iface)
1576 1577 1578 1579 1580 1581
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

1582
static HRESULT WINAPI WMPControls_fastReverse(IWMPControls *iface)
1583 1584 1585 1586 1587 1588
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

1589
static HRESULT WINAPI WMPControls_get_currentPosition(IWMPControls *iface, DOUBLE *pdCurrentPosition)
1590 1591
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602
    HRESULT hres;
    LONGLONG currentPosition;

    TRACE("(%p)->(%p)\n", This, pdCurrentPosition);
    if (!This->media_seeking)
        return S_FALSE;

    hres = IMediaSeeking_GetCurrentPosition(This->media_seeking, &currentPosition);
    *pdCurrentPosition = (DOUBLE) currentPosition / 10000000.0f;
    TRACE("hres: %d, pos: %f\n", hres, *pdCurrentPosition);
    return hres;
1603 1604
}

1605
static HRESULT WINAPI WMPControls_put_currentPosition(IWMPControls *iface, DOUBLE dCurrentPosition)
1606
{
1607 1608
    LONGLONG Current;
    HRESULT hres;
1609
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
1610 1611 1612 1613 1614 1615 1616 1617 1618
    TRACE("(%p)->(%f)\n", This, dCurrentPosition);
    if (!This->media_seeking)
        return S_FALSE;

    Current = 10000000 * dCurrentPosition;
    hres = IMediaSeeking_SetPositions(This->media_seeking, &Current,
            AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);

    return hres;
1619 1620
}

1621
static HRESULT WINAPI WMPControls_get_currentPositionString(IWMPControls *iface, BSTR *pbstrCurrentPosition)
1622 1623 1624 1625 1626 1627
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%p)\n", This, pbstrCurrentPosition);
    return E_NOTIMPL;
}

1628
static HRESULT WINAPI WMPControls_next(IWMPControls *iface)
1629 1630 1631 1632 1633 1634
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

1635
static HRESULT WINAPI WMPControls_previous(IWMPControls *iface)
1636 1637 1638 1639 1640 1641
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

1642
static HRESULT WINAPI WMPControls_get_currentItem(IWMPControls *iface, IWMPMedia **ppIWMPMedia)
1643 1644 1645 1646 1647 1648
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%p)\n", This, ppIWMPMedia);
    return E_NOTIMPL;
}

1649
static HRESULT WINAPI WMPControls_put_currentItem(IWMPControls *iface, IWMPMedia *pIWMPMedia)
1650 1651 1652 1653 1654 1655
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%p)\n", This, pIWMPMedia);
    return E_NOTIMPL;
}

1656
static HRESULT WINAPI WMPControls_get_currentMarker(IWMPControls *iface, LONG *plMarker)
1657 1658 1659 1660 1661 1662
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%p)\n", This, plMarker);
    return E_NOTIMPL;
}

1663
static HRESULT WINAPI WMPControls_put_currentMarker(IWMPControls *iface, LONG lMarker)
1664 1665 1666 1667 1668 1669
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%d)\n", This, lMarker);
    return E_NOTIMPL;
}

1670
static HRESULT WINAPI WMPControls_playItem(IWMPControls *iface, IWMPMedia *pIWMPMedia)
1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702
{
    WindowsMediaPlayer *This = impl_from_IWMPControls(iface);
    FIXME("(%p)->(%p)\n", This, pIWMPMedia);
    return E_NOTIMPL;
}

static const IWMPControlsVtbl WMPControlsVtbl = {
    WMPControls_QueryInterface,
    WMPControls_AddRef,
    WMPControls_Release,
    WMPControls_GetTypeInfoCount,
    WMPControls_GetTypeInfo,
    WMPControls_GetIDsOfNames,
    WMPControls_Invoke,
    WMPControls_get_isAvailable,
    WMPControls_play,
    WMPControls_stop,
    WMPControls_pause,
    WMPControls_fastForward,
    WMPControls_fastReverse,
    WMPControls_get_currentPosition,
    WMPControls_put_currentPosition,
    WMPControls_get_currentPositionString,
    WMPControls_next,
    WMPControls_previous,
    WMPControls_get_currentItem,
    WMPControls_put_currentItem,
    WMPControls_get_currentMarker,
    WMPControls_put_currentMarker,
    WMPControls_playItem,
};

1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744
static HRESULT WINAPI WMPMedia_QueryInterface(IWMPMedia *iface, REFIID riid, void **ppv)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    TRACE("(%p)\n", This);
    if(IsEqualGUID(&IID_IUnknown, riid)) {
        TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
        *ppv = &This->IWMPMedia_iface;
    }else if(IsEqualGUID(&IID_IDispatch, riid)) {
        TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
        *ppv = &This->IWMPMedia_iface;
    }else if(IsEqualGUID(&IID_IWMPMedia, riid)) {
        TRACE("(%p)->(IID_IWMPMedia %p)\n", This, ppv);
        *ppv = &This->IWMPMedia_iface;
    }else {
        WARN("Unsupported interface %s\n", debugstr_guid(riid));
        *ppv = NULL;
        return E_NOINTERFACE;
    }

    IUnknown_AddRef((IUnknown*)*ppv);
    return S_OK;
}

static ULONG WINAPI WMPMedia_AddRef(IWMPMedia *iface)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    LONG ref = InterlockedIncrement(&This->ref);

    TRACE("(%p) ref=%d\n", This, ref);

    return ref;
}

static ULONG WINAPI WMPMedia_Release(IWMPMedia *iface)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    LONG ref = InterlockedDecrement(&This->ref);

    TRACE("(%p) ref=%d\n", This, ref);

    if(!ref) {
        heap_free(This->url);
1745
        heap_free(This->name);
1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791
        heap_free(This);
    }

    return ref;
}

static HRESULT WINAPI WMPMedia_GetTypeInfoCount(IWMPMedia *iface, UINT *pctinfo)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p)\n", This, pctinfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_GetTypeInfo(IWMPMedia *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_GetIDsOfNames(IWMPMedia *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_Invoke(IWMPMedia *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
        EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%d %s %d %x %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), lcid,
          wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_get_isIdentical(IWMPMedia *iface, IWMPMedia *other, VARIANT_BOOL *pvBool)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p, %p)\n", This, other, pvBool);
    return E_NOTIMPL;
}

1792
static HRESULT WINAPI WMPMedia_get_sourceURL(IWMPMedia *iface, BSTR *url)
1793 1794
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
1795 1796 1797 1798

    TRACE("(%p)->(%p)\n", This, url);

    return return_bstr(This->url, url);
1799 1800
}

1801
static HRESULT WINAPI WMPMedia_get_name(IWMPMedia *iface, BSTR *name)
1802 1803
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
1804

1805
    TRACE("(%p)->(%p)\n", This, name);
1806

1807
    return return_bstr(This->name, name);
1808 1809
}

1810
static HRESULT WINAPI WMPMedia_put_name(IWMPMedia *iface, BSTR name)
1811 1812
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
1813 1814 1815 1816 1817

    TRACE("(%p)->(%s)\n", This, debugstr_w(name));

    if (!name) return E_POINTER;

1818
    heap_free(This->name);
1819 1820
    This->name = heap_strdupW(name);
    return S_OK;
1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859
}

static HRESULT WINAPI WMPMedia_get_imageSourceWidth(IWMPMedia *iface, LONG *pWidth)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p)\n", This, pWidth);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_get_imageSourceHeight(IWMPMedia *iface, LONG *pHeight)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p)\n", This, pHeight);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_get_markerCount(IWMPMedia *iface, LONG* pMarkerCount)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p)\n", This, pMarkerCount);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_getMarkerTime(IWMPMedia *iface, LONG MarkerNum, DOUBLE *pMarkerTime)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%d, %p)\n", This, MarkerNum, pMarkerTime);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_getMarkerName(IWMPMedia *iface, LONG MarkerNum, BSTR *pbstrMarkerName)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%d, %p)\n", This, MarkerNum, pbstrMarkerName);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_get_duration(IWMPMedia *iface, DOUBLE *pDuration)
{
1860 1861
    /* MSDN: If this property is used with a media item other than the one
     * specified in Player.currentMedia, it may not contain a valid value. */
1862
    WMPMedia *This = impl_from_IWMPMedia(iface);
1863 1864 1865
    TRACE("(%p)->(%p)\n", This, pDuration);
    *pDuration = This->duration;
    return S_OK;
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888
}

static HRESULT WINAPI WMPMedia_get_durationString(IWMPMedia *iface, BSTR *pbstrDuration)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p)\n", This, pbstrDuration);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_get_attributeCount(IWMPMedia *iface, LONG *plCount)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p)\n", This, plCount);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_getAttributeName(IWMPMedia *iface, LONG lIndex, BSTR *pbstrItemName)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%d, %p)\n", This, lIndex, pbstrItemName);
    return E_NOTIMPL;
}

1889
static HRESULT WINAPI WMPMedia_getItemInfo(IWMPMedia *iface, BSTR item_name, BSTR *value)
1890 1891
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
1892 1893
    FIXME("(%p)->(%s, %p)\n", This, debugstr_w(item_name), value);
    return return_bstr(NULL, value);
1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951
}

static HRESULT WINAPI WMPMedia_setItemInfo(IWMPMedia *iface, BSTR bstrItemName, BSTR bstrVal)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%s, %s)\n", This, debugstr_w(bstrItemName), debugstr_w(bstrVal));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_getItemInfoByAtom(IWMPMedia *iface, LONG lAtom, BSTR *pbstrVal)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%d, %p)\n", This, lAtom, pbstrVal);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_isMemberOf(IWMPMedia *iface, IWMPPlaylist *pPlaylist, VARIANT_BOOL *pvarfIsMemberOf)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%p, %p)\n", This, pPlaylist, pvarfIsMemberOf);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPMedia_isReadOnlyItem(IWMPMedia *iface, BSTR bstrItemName, VARIANT_BOOL *pvarfIsReadOnly)
{
    WMPMedia *This = impl_from_IWMPMedia(iface);
    FIXME("(%p)->(%s, %p)\n", This, debugstr_w(bstrItemName), pvarfIsReadOnly);
    return E_NOTIMPL;
}

static const IWMPMediaVtbl WMPMediaVtbl = {
    WMPMedia_QueryInterface,
    WMPMedia_AddRef,
    WMPMedia_Release,
    WMPMedia_GetTypeInfoCount,
    WMPMedia_GetTypeInfo,
    WMPMedia_GetIDsOfNames,
    WMPMedia_Invoke,
    WMPMedia_get_isIdentical,
    WMPMedia_get_sourceURL,
    WMPMedia_get_name,
    WMPMedia_put_name,
    WMPMedia_get_imageSourceWidth,
    WMPMedia_get_imageSourceHeight,
    WMPMedia_get_markerCount,
    WMPMedia_getMarkerTime,
    WMPMedia_getMarkerName,
    WMPMedia_get_duration,
    WMPMedia_get_durationString,
    WMPMedia_get_attributeCount,
    WMPMedia_getAttributeName,
    WMPMedia_getItemInfo,
    WMPMedia_setItemInfo,
    WMPMedia_getItemInfoByAtom,
    WMPMedia_isMemberOf,
    WMPMedia_isReadOnlyItem
};

1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036
static HRESULT WINAPI WMPPlaylist_QueryInterface(IWMPPlaylist *iface, REFIID riid, void **ppv)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    TRACE("(%p)\n", This);
    if(IsEqualGUID(&IID_IUnknown, riid)) {
        TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
        *ppv = &This->IWMPPlaylist_iface;
    }else if(IsEqualGUID(&IID_IDispatch, riid)) {
        TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
        *ppv = &This->IWMPPlaylist_iface;
    }else if(IsEqualGUID(&IID_IWMPPlaylist, riid)) {
        TRACE("(%p)->(IID_IWMPPlaylist %p)\n", This, ppv);
        *ppv = &This->IWMPPlaylist_iface;
    }else {
        WARN("Unsupported interface %s\n", debugstr_guid(riid));
        *ppv = NULL;
        return E_NOINTERFACE;
    }

    IUnknown_AddRef((IUnknown*)*ppv);
    return S_OK;
}

static ULONG WINAPI WMPPlaylist_AddRef(IWMPPlaylist *iface)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    LONG ref = InterlockedIncrement(&This->ref);

    TRACE("(%p) ref=%d\n", This, ref);

    return ref;
}

static ULONG WINAPI WMPPlaylist_Release(IWMPPlaylist *iface)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    LONG ref = InterlockedDecrement(&This->ref);

    TRACE("(%p) ref=%d\n", This, ref);

    if(!ref) {
        heap_free(This->url);
        heap_free(This->name);
        heap_free(This);
    }

    return ref;
}

static HRESULT WINAPI WMPPlaylist_GetTypeInfoCount(IWMPPlaylist *iface, UINT *pctinfo)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)->(%p)\n", This, pctinfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlaylist_GetTypeInfo(IWMPPlaylist *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlaylist_GetIDsOfNames(IWMPPlaylist *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlaylist_Invoke(IWMPPlaylist *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
        EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)->(%d %s %d %x %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), lcid,
          wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlaylist_get_count(IWMPPlaylist *iface, LONG *count)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
2037 2038 2039 2040 2041 2042 2043

    TRACE("(%p)->(%p)\n", This, count);

    if (!count) return E_POINTER;
    *count = This->count;

    return S_OK;
2044 2045 2046 2047 2048
}

static HRESULT WINAPI WMPPlaylist_get_name(IWMPPlaylist *iface, BSTR *name)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
2049 2050 2051 2052

    TRACE("(%p)->(%p)\n", This, name);

    return return_bstr(This->name, name);
2053 2054 2055 2056 2057
}

static HRESULT WINAPI WMPPlaylist_put_name(IWMPPlaylist *iface, BSTR name)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
2058 2059 2060 2061 2062

    TRACE("(%p)->(%s)\n", This, debugstr_w(name));

    if (!name) return E_POINTER;

2063
    heap_free(This->name);
2064 2065
    This->name = heap_strdupW(name);
    return S_OK;
2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127
}

static HRESULT WINAPI WMPPlaylist_get_attributeCount(IWMPPlaylist *iface, LONG *count)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)->(%p)\n", This, count);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlaylist_get_attributeName(IWMPPlaylist *iface, LONG index, BSTR *attribute_name)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)->(%d %p)\n", This, index, attribute_name);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlaylist_get_Item(IWMPPlaylist *iface, LONG index, IWMPMedia **media)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)->(%d %p)\n", This, index, media);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlaylist_getItemInfo(IWMPPlaylist *iface, BSTR name, BSTR *value)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), value);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlaylist_setItemInfo(IWMPPlaylist *iface, BSTR name, BSTR value)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)->(%s %s)\n", This, debugstr_w(name), debugstr_w(value));
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlaylist_get_isIdentical(IWMPPlaylist *iface, IWMPPlaylist *playlist, VARIANT_BOOL *var)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)->(%p %p)\n", This, playlist, var);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlaylist_clear(IWMPPlaylist *iface)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlaylist_insertItem(IWMPPlaylist *iface, LONG index, IWMPMedia *media)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)->(%d %p)\n", This, index, media);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlaylist_appendItem(IWMPPlaylist *iface, IWMPMedia *media)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)->(%p)\n", This, media);
2128
    return S_OK;
2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168
}

static HRESULT WINAPI WMPPlaylist_removeItem(IWMPPlaylist *iface, IWMPMedia *media)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)->(%p)\n", This, media);
    return E_NOTIMPL;
}

static HRESULT WINAPI WMPPlaylist_moveItem(IWMPPlaylist *iface, LONG old_index, LONG new_index)
{
    WMPPlaylist *This = impl_from_IWMPPlaylist(iface);
    FIXME("(%p)->(%d %d)\n", This, old_index, new_index);
    return E_NOTIMPL;
}

static const IWMPPlaylistVtbl WMPPlaylistVtbl = {
    WMPPlaylist_QueryInterface,
    WMPPlaylist_AddRef,
    WMPPlaylist_Release,
    WMPPlaylist_GetTypeInfoCount,
    WMPPlaylist_GetTypeInfo,
    WMPPlaylist_GetIDsOfNames,
    WMPPlaylist_Invoke,
    WMPPlaylist_get_count,
    WMPPlaylist_get_name,
    WMPPlaylist_put_name,
    WMPPlaylist_get_attributeCount,
    WMPPlaylist_get_attributeName,
    WMPPlaylist_get_Item,
    WMPPlaylist_getItemInfo,
    WMPPlaylist_setItemInfo,
    WMPPlaylist_get_isIdentical,
    WMPPlaylist_clear,
    WMPPlaylist_insertItem,
    WMPPlaylist_appendItem,
    WMPPlaylist_removeItem,
    WMPPlaylist_moveItem
};

2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200
static LRESULT WINAPI player_wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    if (msg == WM_WMPEVENT && wParam == 0) {
        WindowsMediaPlayer *wmp = (WindowsMediaPlayer*)lParam;
        LONG event_code;
        LONG_PTR p1, p2;
        HRESULT hr;
        if (wmp->media_event) {
            do {
                hr = IMediaEvent_GetEvent(wmp->media_event, &event_code, &p1, &p2, 0);
                if (SUCCEEDED(hr)) {
                    TRACE("got event_code = 0x%02x\n", event_code);
                    IMediaEvent_FreeEventParams(wmp->media_event, event_code, p1, p2);
                    /* For now we only handle EC_COMPLETE */
                    if (event_code == EC_COMPLETE) {
                        update_state(wmp, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsMediaEnded);
                        update_state(wmp, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsTransitioning);
                        update_state(wmp, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsStopped);
                    }
                }
            } while (hr == S_OK);
        } else {
            FIXME("Got event from quartz when interfaces are already released\n");
        }
    }
    return DefWindowProcW(hwnd, msg, wParam, lParam);
}

static BOOL WINAPI register_player_msg_class(INIT_ONCE *once, void *param, void **context) {
    static WNDCLASSEXW wndclass = {
        sizeof(wndclass), CS_DBLCLKS, player_wnd_proc, 0, 0,
        NULL, NULL, NULL, NULL, NULL,
2201
        L"_WMPMessage", NULL
2202 2203 2204 2205
    };

    wndclass.hInstance = wmp_instance;
    player_msg_class = RegisterClassExW(&wndclass);
2206
    WM_WMPEVENT= RegisterWindowMessageW(L"_WMPMessage");
2207 2208 2209 2210 2211 2212 2213 2214 2215
    return TRUE;
}

void unregister_player_msg_class(void) {
    if(player_msg_class)
        UnregisterClassW(MAKEINTRESOURCEW(player_msg_class), wmp_instance);
}

BOOL init_player(WindowsMediaPlayer *wmp)
2216
{
2217
    IWMPPlaylist *playlist;
2218
    BSTR name;
2219

2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231
    InitOnceExecuteOnce(&class_init_once, register_player_msg_class, NULL, NULL);
    wmp->msg_window = CreateWindowW( MAKEINTRESOURCEW(player_msg_class), NULL, 0, 0,
            0, 0, 0, HWND_MESSAGE, 0, wmp_instance, wmp );
    if (!wmp->msg_window) {
        ERR("Failed to create message window, GetLastError: %d\n", GetLastError());
        return FALSE;
    }
    if (!WM_WMPEVENT) {
        ERR("Failed to register window message, GetLastError: %d\n", GetLastError());
        return FALSE;
    }

2232
    wmp->IWMPPlayer4_iface.lpVtbl = &WMPPlayer4Vtbl;
2233
    wmp->IWMPPlayer_iface.lpVtbl = &WMPPlayerVtbl;
2234
    wmp->IWMPSettings_iface.lpVtbl = &WMPSettingsVtbl;
2235
    wmp->IWMPControls_iface.lpVtbl = &WMPControlsVtbl;
2236
    wmp->IWMPNetwork_iface.lpVtbl = &WMPNetworkVtbl;
2237

2238
    name = SysAllocString(L"Playlist1");
2239
    if (SUCCEEDED(create_playlist(name, NULL, 0, &playlist)))
2240 2241 2242
        wmp->playlist = unsafe_impl_from_IWMPPlaylist(playlist);
    else
        wmp->playlist = NULL;
2243
    SysFreeString(name);
2244

2245 2246
    wmp->invoke_urls = VARIANT_TRUE;
    wmp->auto_start = VARIANT_TRUE;
2247
    wmp->volume = 100;
2248
    return TRUE;
2249
}
2250 2251 2252

void destroy_player(WindowsMediaPlayer *wmp)
{
2253
    IWMPControls_stop(&wmp->IWMPControls_iface);
2254 2255
    if (wmp->media)
        IWMPMedia_Release(&wmp->media->IWMPMedia_iface);
2256 2257
    if (wmp->playlist)
        IWMPPlaylist_Release(&wmp->playlist->IWMPPlaylist_iface);
2258
    DestroyWindow(wmp->msg_window);
2259 2260
}

2261 2262 2263 2264 2265 2266 2267
WMPMedia *unsafe_impl_from_IWMPMedia(IWMPMedia *iface)
{
    if (iface->lpVtbl == &WMPMediaVtbl) {
        return CONTAINING_RECORD(iface, WMPMedia, IWMPMedia_iface);
    }
    return NULL;
}
2268

2269 2270 2271 2272 2273 2274 2275 2276
WMPPlaylist *unsafe_impl_from_IWMPPlaylist(IWMPPlaylist *iface)
{
    if (iface->lpVtbl == &WMPPlaylistVtbl) {
        return CONTAINING_RECORD(iface, WMPPlaylist, IWMPPlaylist_iface);
    }
    return NULL;
}

2277
HRESULT create_media_from_url(BSTR url, double duration, IWMPMedia **ppMedia)
2278
{
2279
    WMPMedia *media;
2280 2281 2282
    IUri *uri;
    BSTR path;
    HRESULT hr;
2283
    WCHAR *name_dup;
2284

2285 2286
    media = heap_alloc_zero(sizeof(*media));
    if (!media)
2287 2288
        return E_OUTOFMEMORY;

2289
    media->IWMPMedia_iface.lpVtbl = &WMPMediaVtbl;
2290 2291 2292 2293 2294 2295 2296 2297 2298 2299

    if (url)
    {
        media->url = heap_strdupW(url);
        name_dup = heap_strdupW(url);

        hr = CreateUri(name_dup, Uri_CREATE_ALLOW_RELATIVE | Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME, 0, &uri);
        if (FAILED(hr))
        {
            heap_free(name_dup);
2300
            IWMPMedia_Release(&media->IWMPMedia_iface);
2301 2302 2303 2304 2305 2306 2307
            return hr;
        }
        hr = IUri_GetPath(uri, &path);
        if (hr != S_OK)
        {
            heap_free(name_dup);
            IUri_Release(uri);
2308
            IWMPMedia_Release(&media->IWMPMedia_iface);
2309 2310 2311 2312 2313 2314
            return hr;
        }

        /* GetPath() will return "/" for invalid uri's
         * only strip extension when uri is valid
         */
2315
        if (wcscmp(path, L"/") != 0)
2316 2317 2318 2319 2320 2321 2322 2323 2324 2325
            PathRemoveExtensionW(name_dup);
        PathStripPathW(name_dup);

        media->name = name_dup;

        SysFreeString(path);
        IUri_Release(uri);
    }
    else
    {
2326 2327
        media->url = heap_strdupW(L"");
        media->name = heap_strdupW(L"");
2328 2329
    }

2330
    media->duration = duration;
2331 2332
    media->ref = 1;

2333 2334 2335 2336 2337 2338 2339
    if (media->url) {
        *ppMedia = &media->IWMPMedia_iface;

        return S_OK;
    }
    IWMPMedia_Release(&media->IWMPMedia_iface);
    return E_OUTOFMEMORY;
2340
}
2341

2342
HRESULT create_playlist(BSTR name, BSTR url, LONG count, IWMPPlaylist **ppPlaylist)
2343 2344 2345 2346 2347 2348 2349 2350
{
    WMPPlaylist *playlist;

    playlist = heap_alloc_zero(sizeof(*playlist));
    if (!playlist)
        return E_OUTOFMEMORY;

    playlist->IWMPPlaylist_iface.lpVtbl = &WMPPlaylistVtbl;
2351 2352
    playlist->url = heap_strdupW(url ? url : L"");
    playlist->name = heap_strdupW(name ? name : L"");
2353
    playlist->ref = 1;
2354
    playlist->count = count;
2355 2356 2357 2358 2359 2360 2361 2362 2363 2364

    if (playlist->url)
    {
        *ppPlaylist = &playlist->IWMPPlaylist_iface;
        return S_OK;
    }

    IWMPPlaylist_Release(&playlist->IWMPPlaylist_iface);
    return E_OUTOFMEMORY;
}